mirror of
https://gitgud.io/yats/cerberus.git
synced 2026-05-02 02:32:18 -04:00
Add challenge page parser util
This commit is contained in:
18
http.go
18
http.go
@@ -70,6 +70,21 @@ func NewChallenge(ctx context.Context, hc http.Client, host string) (Challenge,
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func ParseChallenge(r io.Reader, host string) (Challenge, error) {
|
||||
u, err := parseHost(host)
|
||||
if err != nil {
|
||||
return Challenge{}, err
|
||||
}
|
||||
|
||||
c, err := parseTags(r)
|
||||
if err != nil {
|
||||
return Challenge{}, err
|
||||
}
|
||||
c.host = u
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Submit a Solution for a Challenge.
|
||||
//
|
||||
// If redirect is empty, "/" is used as a sensible default.
|
||||
@@ -137,8 +152,7 @@ func postSolution(ctx context.Context, hc http.Client, s Solution) (*http.Respon
|
||||
// TODO: Additionally verify failure from response JSON. Maybe include resp body in err type.
|
||||
// Rejected solution response: status=400 body={"success":false,"reason":"invalid_solution","action":"retry"}
|
||||
if resp.StatusCode == 400 {
|
||||
defer resp.Body.Close()
|
||||
return nil, &ErrInvalidSolution{s}
|
||||
return resp, &ErrInvalidSolution{s}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
Reference in New Issue
Block a user