Skip to content

Commit

Permalink
fix: login/logout session cookie handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Apr 15, 2024
1 parent f3e57e8 commit b14477b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@ func (client *Client) Login(params *LoginParams, opts ...Option) error {
return err
}
client.nonce = nonce

u, _ := url.Parse(client.url)
hds := client.sub.Jar.Cookies(u)
for _, hd := range hds {
if hd.Name == "session" {
client.session = hd.Value
break
}
}

return nil
}
11 changes: 11 additions & 0 deletions api/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"fmt"
"net/http"
"net/url"
)

func (client *Client) Logout(opts ...Option) error {
Expand All @@ -23,5 +24,15 @@ func (client *Client) Logout(opts ...Option) error {
return err
}
client.nonce = nonce

u, _ := url.Parse(client.url)
hds := client.sub.Jar.Cookies(u)
for _, hd := range hds {
if hd.Name == "session" {
client.session = hd.Value
break
}
}

return nil
}
3 changes: 2 additions & 1 deletion api/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ func Test_F_Setup(t *testing.T) {
return
}

// 1e. Relog :)
// 1e. Relog, and drop the use of the API token because... why not ¯\_(ツ)_/¯
err = client.Login(&api.LoginParams{
Name: "ctfer",
Password: "password",
})
if !assert.Nil(err, "got error: %s", err) {
return
}
client.SetAPIKey("")

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

0 comments on commit b14477b

Please sign in to comment.