Skip to content

Commit

Permalink
fix: login endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Apr 15, 2024
1 parent bdd6ba3 commit 49ad750
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func NewClient(url, nonce, session, apiKey string) *Client {
return &Client{
sub: &http.Client{
Jar: jar,
// Don't follow redirections
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
// // Don't follow redirections
// CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
// return http.ErrUseLastResponse
// },
},
url: url,
nonce: nonce,
Expand Down
11 changes: 1 addition & 10 deletions api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"net/http"
"net/url"

"github.com/pkg/errors"
)

type LoginParams struct {
Expand Down Expand Up @@ -45,12 +43,5 @@ func (client *Client) Login(params *LoginParams, opts ...Option) error {
return err
}
client.nonce = nonce

for _, cookie := range res.Cookies() {
if cookie.Name == "session" {
client.session = cookie.Value
return nil
}
}
return errors.New("session cookie not found")
return nil
}
15 changes: 15 additions & 0 deletions api/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ func Test_F_Setup(t *testing.T) {
}
client.SetAPIKey(*token.Value)

// 1d. Logout because we don't know what could happen with a mouse on the UI
err = client.Logout()
if !assert.Nil(err, "got error: %s", err) {
return
}

// 1e. Relog :)
err = client.Login(&api.LoginParams{
Name: "ctfer",
Password: "password",
})
if !assert.Nil(err, "got error: %s", err) {
return
}

// 2. Create a challenge
chall, err := client.PostChallenges(&api.PostChallengesParams{
Name: "Stealing data",
Expand Down

0 comments on commit 49ad750

Please sign in to comment.