Skip to content

Commit

Permalink
Merge pull request #140 from antham/fix-flush-inbox-failure
Browse files Browse the repository at this point in the history
Fix failure when fetching an inbox
  • Loading branch information
antham authored Dec 27, 2023
2 parents 7de8fdf + a371644 commit cbbd694
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func wrapError(msg string, err error) error {
}

func checkInboxCAPTCHA(content string) error {
s := `w\.finrmail\(\d+,\s*\d+,\s*\d+,\s*\d+,\s*\d+,\s*'alt\.[^']+',\s*'.*?'\)`
s := `w\.finrmail\(\d+,\s*\d+,\s*\d+,\s*\d+,\s*\d+,\s*'alt\.[^']+',\s*'.*?'\)|Loading \.\.\.`
if !regexp.MustCompile(s).MatchString(content) {
return ErrCaptcha
}
Expand Down
34 changes: 33 additions & 1 deletion internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,42 @@ func TestHTTPClientFactoryCreate(t *testing.T) {
}
}

func TestCheckInboxCAPTCHA(t *testing.T) {
type scenario struct {
name string
arg string
test func(error)
}

for _, s := range []scenario{{
"No captcha because loading is defined",
"Loading ...",
func(err error) {
assert.NoError(t, err)
},
}, {
"No captcha because finrmail is defined",
`w.finrmail(699,2,1,1,0,'alt.xm-doh3nzhv','')`,
func(err error) {
assert.NoError(t, err)
},
}, {
"Captcha activated",
``,
func(err error) {
assert.Error(t, err)
},
}} {
t.Run(s.name, func(t *testing.T) {
err := checkInboxCAPTCHA(s.arg)
s.test(err)
})
}
}

func mockYopmailSetup() {
httpmock.RegisterResponder("GET", refURL+"/ver/3.1/webmail.js",
httpmock.NewStringResponder(200, "xxx http://whatever.com?q=s&yj=ytest&t=a xxxxx"))
httpmock.RegisterResponder("GET", refURL+"/consent?c=accept", httpmock.NewStringResponder(200, ""))
httpmock.RegisterResponder("GET", refURL,
httpmock.NewStringResponder(200, `<script src="/ver/3.1/webmail.js"></script><input id="yp" value="yptest">`))
}

0 comments on commit cbbd694

Please sign in to comment.