Skip to content

Commit

Permalink
build: configure webauthn origin using Rails configurations (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagorodriguez96 authored Mar 29, 2024
1 parent fe83a4d commit 9bbd81a
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN=
ROLLBAR_POST_CLIENT_ITEM_ACCESS_TOKEN=
WEBAUTHN_ORIGIN=http://localhost:3000
1 change: 0 additions & 1 deletion .env.test

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def current_user
def relying_party
@relying_party ||=
WebAuthn::RelyingParty.new(
origin: ENV["WEBAUTHN_ORIGIN"],
origin: Rails.configuration.webauthn_origin,
name: "WebAuthn Rails Demo App"
)
end
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

config.webauthn_origin = 'http://localhost:3000'
end
4 changes: 3 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.middleware.use(Rack::HostRedirect, "webauthn.herokuapp.com" => URI(ENV["WEBAUTHN_ORIGIN"]).host)
config.webauthn_origin = 'https://webauthn.cedarcode.com'

config.middleware.use(Rack::HostRedirect, "webauthn.herokuapp.com" => URI(config.webauthn_origin).host)
end
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

config.webauthn_origin = 'http://localhost:3030'
end
2 changes: 1 addition & 1 deletion test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: (ENV["TEST_BROWSER"] || :chrome).to_sym, screen_size: [1400, 1400]

setup do
Capybara.app_host = ENV['WEBAUTHN_ORIGIN']
Capybara.app_host = Rails.configuration.webauthn_origin
Capybara.server_host = "localhost"
Capybara.server_port = 3030
Capybara.default_max_wait_time = 20
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/registrations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest

public_key_credential =
WebAuthn::FakeClient
.new(ENV["WEBAUTHN_ORIGIN"])
.new(Rails.configuration.webauthn_origin)
.create(challenge: challenge, user_verified: true)

webauthn_credential = WebAuthn::Credential.from_create(public_key_credential)
Expand Down
2 changes: 1 addition & 1 deletion test/system/add_credential_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class AddCredentialTest < ApplicationSystemTestCase
test "add credentials" do
fake_origin = ENV['WEBAUTHN_ORIGIN']
fake_origin = Rails.configuration.webauthn_origin
fake_client = WebAuthn::FakeClient.new(fake_origin, encoding: false)
fixed_challenge = SecureRandom.random_bytes(32)

Expand Down
2 changes: 1 addition & 1 deletion test/system/registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class RegistrationTest < ApplicationSystemTestCase
test "register user" do
fake_origin = ENV['WEBAUTHN_ORIGIN']
fake_origin = Rails.configuration.webauthn_origin
fake_client = WebAuthn::FakeClient.new(fake_origin, encoding: false)
fixed_challenge = SecureRandom.random_bytes(32)

Expand Down
2 changes: 1 addition & 1 deletion test/system/sign_in_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class SignInTest < ApplicationSystemTestCase
test "register and then sign in" do
fake_origin = ENV['WEBAUTHN_ORIGIN']
fake_origin = Rails.configuration.webauthn_origin
fake_client = WebAuthn::FakeClient.new(fake_origin, encoding: false)
fixed_challenge = SecureRandom.random_bytes(32)

Expand Down

0 comments on commit 9bbd81a

Please sign in to comment.