Skip to content

Commit 59193e7

Browse files
committed
Ensured tokens are different on each login with Test
1 parent 4c15590 commit 59193e7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

spec/requests/api/v1/users/sessions_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@
2828
end
2929
end
3030

31+
response "201", "generates new randomized tokens on each sign-in" do
32+
let(:user) { { email: volunteer.email, password: volunteer.password } }
33+
schema "$ref" => "#/components/schemas/login_success"
34+
35+
run_test! do |response|
36+
first_response = JSON.parse(response.body)
37+
38+
expect(response.status).to eq(201)
39+
expect(first_response["token"]).not_to be_nil
40+
expect(first_response["refresh_token"]).not_to be_nil
41+
42+
old_token = first_response["token"]
43+
old_refresh_token = first_response["refresh_token"]
44+
45+
# Second Sign-In
46+
post "/api/v1/users/sign_in", params: user
47+
second_response = JSON.parse(response.body)
48+
49+
expect(response.status).to eq(201)
50+
expect(second_response["token"]).not_to eq(old_token)
51+
expect(second_response["refresh_token"]).not_to eq(old_refresh_token)
52+
end
53+
end
54+
55+
3156
response "401", "invalid credentials" do
3257
let(:user) { {email: "foo", password: "bar"} }
3358
schema "$ref" => "#/components/schemas/login_failure"

swagger/v1/swagger.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ components:
1616
type: string
1717
token:
1818
type: string
19+
refresh_token:
20+
type: string
21+
token_expires_at:
22+
type: datetime
23+
refresh_token_expires_at:
24+
type: datetime
1925
login_failure:
2026
type: object
2127
properties:

0 commit comments

Comments
 (0)