-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
حمید رضا حسنی یاقوتی
authored and
حمید رضا حسنی یاقوتی
committed
Nov 10, 2020
1 parent
ad1b8cd
commit 12d8bcb
Showing
5 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
ic "github.com/IrisDev-net/irisCaptchaGo" | ||
) | ||
|
||
const myIrisCaptchaSecret = `533a64afb4c496cc34dfd00d1ecbd45cfa2784b2c3eba4aa02e7a4dcbe081aa40x2711` | ||
|
||
func main() { | ||
ICH, err := ic.NewIrisCaptchaHandler(myIrisCaptchaSecret) | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
c := r.FormValue("irisCaptcha") | ||
//! !DOSE NOT RECOMMENDED - for validation without ip Checking | ||
// res, err := ICH.Validate(c, "") | ||
|
||
// * Note that is not working on local host, if you want to test it on your localhost use ICH.Validate(c, "") instead. | ||
res, err := ICH.Validate(c, r.RemoteAddr) | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
if !res.Success { | ||
w.Write([]byte("Wrong Captcha Answer")) | ||
return | ||
} else { | ||
w.Write([]byte("Hooraa Captcha is Solved Correctly")) | ||
return | ||
} | ||
|
||
}) | ||
|
||
http.ListenAndServe(":8090", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/IrisDev-net/irisCaptchaGo | ||
|
||
go 1.15 | ||
|
||
require github.com/dgrijalva/jwt-go v3.2.0+incompatible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM= | ||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= | ||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package iriscaptchago | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestNewIrisCaptchaHandler(t *testing.T) { | ||
var secretCases = []struct { | ||
secret string | ||
want error | ||
}{ | ||
{"", ErrInvalidSecret}, | ||
{"abcabcabc", ErrInvalidSecret}, | ||
{"533a64afb4c496ca4dcbe081aa40x2711", nil}, | ||
{"533a64afb4c496ca4dcb0x2711e081aa40x2711", nil}, | ||
} | ||
|
||
for _, tt := range secretCases { | ||
testname := fmt.Sprintf("%s\n", tt.secret) | ||
t.Run(testname, func(t *testing.T) { | ||
_, err := NewIrisCaptchaHandler(tt.secret) | ||
if err != tt.want { | ||
t.Errorf("got %v, want %v", err, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
func TestGetJs(t *testing.T) { | ||
|
||
c, err := NewIrisCaptchaHandler("533a64afb4c496ca4dcb0x2711e081aa40x2711") | ||
if err != nil { | ||
t.Errorf("got %v, want %v", err, nil) | ||
} | ||
ans := c.GetJs() | ||
const cres = `<script src="https://captcha.irisdev.net/js/0x2711></script>` | ||
if ans != cres { | ||
t.Errorf("got %s, want %s", ans, cres) | ||
} | ||
} | ||
func TestLoadPublicKey(t *testing.T) { | ||
c := new(irisCaptchaHandler) | ||
c.provider = IrisDevServer | ||
err := c.loadPublicKey() | ||
if err != nil { | ||
t.Errorf("got %v, want %v", err, nil) | ||
} | ||
} | ||
|
||
func TestValidateReq(t *testing.T) { | ||
c, err := NewIrisCaptchaHandler("533a64afb4c496cc34dfd00d1ecbd45cfa2784b2c3eba4aa02e7a4dcbe081aa40x2711") | ||
if err != nil { | ||
t.Errorf("got %v, want %v", err, nil) | ||
} | ||
h := c.(*irisCaptchaHandler) | ||
h.TestValidateReq(t) | ||
h.TestValidateSig(t) | ||
|
||
} |