|
31 | 31 | context "when user is authenticated" do |
32 | 32 | before do |
33 | 33 | sign_in user, scope: :account |
34 | | - get options_for_create_account_passkeys_path # To set the challenge in session |
| 34 | + get account_passkeys_registration_options_path # To set the challenge in session |
35 | 35 | end |
36 | 36 |
|
37 | 37 | context "with valid parameters" do |
|
118 | 118 | end |
119 | 119 | end |
120 | 120 | end |
121 | | - |
122 | | - # rubocop:disable RSpec/MultipleExpectations |
123 | | - describe "GET #options_for_get" do |
124 | | - it "returns authentication options and stores the challenge in the session" do |
125 | | - get options_for_get_account_passkeys_path |
126 | | - |
127 | | - expect(response).to have_http_status(:ok) |
128 | | - expect(response.media_type).to eq("application/json") |
129 | | - |
130 | | - body = response.parsed_body |
131 | | - expect(body).to include("challenge") |
132 | | - expect(session[:authentication_challenge]).to be_present |
133 | | - end |
134 | | - end |
135 | | - |
136 | | - describe "GET #options_for_create" do |
137 | | - context "when user is authenticated" do |
138 | | - before do |
139 | | - sign_in user, scope: :account |
140 | | - end |
141 | | - |
142 | | - it "returns passkey creation options and stores the challenge in the session" do |
143 | | - get options_for_create_account_passkeys_path |
144 | | - |
145 | | - expect(response).to have_http_status(:ok) |
146 | | - expect(response.media_type).to eq("application/json") |
147 | | - |
148 | | - body = response.parsed_body |
149 | | - expect(body).to include("challenge") |
150 | | - expect(body.dig("user", "name")).to eq(user.email) |
151 | | - expect(session[:webauthn_challenge]).to be_present |
152 | | - end |
153 | | - |
154 | | - it "includes existing passkeys in the excludeCredentials list" do |
155 | | - user.passkeys.create!( |
156 | | - external_id: "existing-external-id", |
157 | | - name: "Existing Passkey", |
158 | | - public_key: "public-key", |
159 | | - sign_count: 0 |
160 | | - ) |
161 | | - |
162 | | - get options_for_create_account_passkeys_path |
163 | | - |
164 | | - body = response.parsed_body |
165 | | - exclude_credentials = body["excludeCredentials"] || [] |
166 | | - |
167 | | - expect(exclude_credentials.size).to eq(user.passkeys.count) |
168 | | - end |
169 | | - end |
170 | | - |
171 | | - context "when user is not authenticated" do |
172 | | - it "redirects to the sign-in page" do |
173 | | - get options_for_create_account_passkeys_path |
174 | | - expect(response).to redirect_to(new_account_session_path) |
175 | | - end |
176 | | - end |
177 | | - end |
178 | | - # rubocop:enable RSpec/MultipleExpectations |
179 | 121 | end |
0 commit comments