|
60 | 60 | end |
61 | 61 |
|
62 | 62 | it "should return a valid authentication token" do |
63 | | - session_cookie = response.headers['set-cookie'] |
64 | | - expect(session_cookie).to match(/^forest_session_token=[^;]+; path=\/; expires=[^;]+; secure; HttpOnly; SameSite=None$/) |
| 63 | + body = JSON.parse(response.body, :symbolize_names => true); |
65 | 64 |
|
66 | | - token = session_cookie.match(/^forest_session_token=([^;]+);/)[1] |
| 65 | + token = body[:token] |
67 | 66 | decoded = JWT.decode(token, ForestLiana.auth_secret, true, { algorithm: 'HS256' })[0] |
68 | 67 |
|
69 | 68 | expected_token_data = { |
|
76 | 75 | } |
77 | 76 |
|
78 | 77 | expect(decoded).to include(expected_token_data) |
79 | | - expect(JSON.parse(response.body, :symbolize_names => true)).to eq({ token: token, tokenData: decoded.deep_symbolize_keys! }) |
| 78 | + expect(body).to eq({ token: token, tokenData: decoded.deep_symbolize_keys! }) |
80 | 79 | expect(response).to have_http_status(200) |
81 | 80 | end |
82 | 81 | end |
83 | 82 |
|
84 | 83 | describe "POST /authentication/logout" do |
85 | 84 | before() do |
86 | | - cookies['forest_session_token'] = { |
87 | | - value: 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6NjY2LCJlbWFpbCI6ImFsaWNlQGZvcmVzdGFkbWluLmNvbSIsImZpcnN0X25hbWUiOiJBbGljZSIsImxhc3RfbmFtZSI6IkRvZSIsInRlYW0iOjEsInJlbmRlcmluZ19pZCI6IjQyIiwiZXhwIjoxNjA4MDQ5MTI2fQ.5xaMxjUjE3wKldBsj3wW0BP9GHnnMqQi2Kpde8cIHEw', |
88 | | - path: '/', |
89 | | - expires: Time.now.to_i + 14.days, |
90 | | - secure: true, |
91 | | - httponly: true |
92 | | - } |
93 | 85 | post ForestLiana::Engine.routes.url_helpers.authentication_logout_path, params: { :renderingId => 42 }, :headers => headers |
94 | | - cookies.delete('forest_session_token') |
95 | 86 | end |
96 | 87 |
|
97 | 88 | it "should respond with a 204 code" do |
98 | 89 | expect(response).to have_http_status(204) |
99 | 90 | end |
100 | | - |
101 | | - it "should invalidate token from browser" do |
102 | | - invalidated_session_cookie = response.headers['set-cookie'] |
103 | | - expect(invalidated_session_cookie).to match(/^forest_session_token=[^;]+; path=\/; expires=Thu, 01 Jan 1970 00:00:00 GMT; secure; HttpOnly; SameSite=None$/) |
104 | | - end |
105 | 91 | end |
106 | 92 | end |
0 commit comments