57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.nite07.com/nite/flaresolverr"
|
|
)
|
|
|
|
func TestGetV1(t *testing.T) {
|
|
f, err := flaresolverr.GetInstance("http://127.0.0.1:8191", "", "")
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
resp, err := f.GetV1("https://nopecha.com/demo/cloudflare", nil)
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
if resp.Solution.Status != 200 {
|
|
t.Fail()
|
|
} else {
|
|
jsonBytes, _ := json.Marshal(resp)
|
|
t.Log(string(jsonBytes))
|
|
}
|
|
}
|
|
|
|
func TestImitateGet(t *testing.T) {
|
|
f, err := flaresolverr.GetInstance("http://127.0.0.1:8191", "", "")
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
resp, err := f.GetV1("https://nopecha.com/demo/cloudflare", nil) // get cf-clearance cookie
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
if resp.Solution.Status != 200 {
|
|
t.FailNow()
|
|
}
|
|
cookies := resp.Solution.Cookies
|
|
resp1, err := f.SimulateGet("https://nopecha.com/demo/cloudflare", &flaresolverr.SimulateOptions{
|
|
HttpCookies: cookies,
|
|
}) // ImitateGet uses cookies to simulate browser requests and also simulates the browser's ja3 fingerprint.
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
if resp1.Status != 200 {
|
|
t.FailNow()
|
|
}
|
|
jsonBytes, _ := json.Marshal(resp1)
|
|
t.Log(string(jsonBytes))
|
|
}
|