Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep cookies in store #556

Merged
merged 15 commits into from
Jul 17, 2023
Merged

Keep cookies in store #556

merged 15 commits into from
Jul 17, 2023

Conversation

k2tzumi
Copy link
Collaborator

@k2tzumi k2tzumi commented Jul 15, 2023

refs #548

/cookies:
get:
headers:
Cookie: "{{ cookies['httpbin.org'][0].Raw }};"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hosts change from environment to environment, so we may need the ability to identify them.

#555

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

keyMap[c.Name] = c
}

d[httpStoreCookieKey] = keyMap
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no SetCookie in the response header, should I explicitly set an empty slice?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think empty slice is necessary because it doesn't become panic even if it is nil, but I thought it would be better to have empty map set.

runn/store.go

Line 131 in 867ca0c

store := map[string]any{}

runn/store.go

Lines 155 to 157 in 867ca0c

s.steps = []map[string]any{}
s.stepMapKeys = []string{}
s.stepMap = map[string]map[string]any{}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this
9d2c60c

[]*http.Cookie{&cookie5},
map[string]map[string]*http.Cookie{
// Expire
"example.com": {},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once all cookies are deleted, should I also delete the domain key itself?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion on this point.

So I tried it in Chrome.

I erased all cookies, but the domain on the display remained.
CleanShot 2023-07-17 at 08 11 01@2x

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into this!
Gives me more confidence in these specs.

@k2tzumi k2tzumi marked this pull request as ready for review July 16, 2023 04:50
@github-actions

This comment has been minimized.

Comment on lines +24 to +25
&& current.res.cookies[vars.cookie.key].Name == vars.cookie.key
&& current.res.cookies[vars.cookie.key].Value == uuid
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When accessing the cookie of a step, the domain key is not needed because the domain of the request is obvious.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!!!

/cookies:
get:
headers:
Cookie: "{{ cookies[url('${HTTPBIN_END_POINT:-https://httpbin.org/}').Host][vars.cookie.key].Raw }};"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to consider addressing this in the following Issue as it is a redundant description
#555

@k2tzumi k2tzumi requested a review from k1LoW July 16, 2023 04:55
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GREAT!!!

I have one modification request, but it is basically LGTM!

keyMap[c.Name] = c
}

d[httpStoreCookieKey] = keyMap
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think empty slice is necessary because it doesn't become panic even if it is nil, but I thought it would be better to have empty map set.

runn/store.go

Line 131 in 867ca0c

store := map[string]any{}

runn/store.go

Lines 155 to 157 in 867ca0c

s.steps = []map[string]any{}
s.stepMapKeys = []string{}
s.stepMap = map[string]map[string]any{}

keyMap = make(map[string]*http.Cookie)
}
if !cookie.Expires.IsZero() && cookie.Expires.Before(time.Now()) {
// Remove expired cookie
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

[]*http.Cookie{&cookie5},
map[string]map[string]*http.Cookie{
// Expire
"example.com": {},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion on this point.

So I tried it in Chrome.

I erased all cookies, but the domain on the display remained.
CleanShot 2023-07-17 at 08 11 01@2x

Comment on lines +24 to +25
&& current.res.cookies[vars.cookie.key].Name == vars.cookie.key
&& current.res.cookies[vars.cookie.key].Value == uuid
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!!!

body: null
test: |
current.res.status == 200
&& current.res.body.cookies[vars.cookie.key] == uuid
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it needs a new line at the end.

CleanShot 2023-07-17 at 08 13 27@2x

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@k1LoW k1LoW added the enhancement New feature or request label Jul 16, 2023
@github-actions
Copy link
Contributor

Code Metrics Report

main (867ca0c) #556 (0ebb0af) +/-
Coverage 69.1% 69.3% +0.2%
Code to Test Ratio 1:0.7 1:0.7 +0.0
Test Execution Time 4m48s 2m36s -2m12s
Details
  |                     | main (867ca0c) | #556 (0ebb0af) |  +/-   |
  |---------------------|----------------|----------------|--------|
+ | Coverage            |          69.1% |          69.3% |  +0.2% |
  |   Files             |             48 |             49 |     +1 |
  |   Lines             |           5010 |           5043 |    +33 |
+ |   Covered           |           3461 |           3493 |    +32 |
+ | Code to Test Ratio  |          1:0.7 |          1:0.7 |   +0.0 |
  |   Code              |          10032 |          10093 |    +61 |
+ |   Test              |           6544 |           6816 |   +272 |
+ | Test Execution Time |          4m48s |          2m36s | -2m12s |

Code coverage of files in pull request scope (75.8% → 76.2%)

Files Coverage +/-
builtin/url.go 0.0% 0.0%
http.go 81.8% +1.0%
operator.go 81.1% +0.2%
option.go 62.9% +0.1%
store.go 92.8% +2.8%

Reported by octocov

Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@k2tzumi
Copy link
Collaborator Author

k2tzumi commented Jul 17, 2023

I would like to consider including it in the README in phase 2
#548 (comment)

@k2tzumi k2tzumi merged commit 7bce570 into main Jul 17, 2023
@k2tzumi k2tzumi deleted the store-cookies branch July 17, 2023 00:09
@github-actions github-actions bot mentioned this pull request Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants