diff --git a/.gitignore b/.gitignore index 40a762c..a12ff0f 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ /coverage # Ignore encrypted secrets key file. config/secrets.yml.key + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index e64d703..3efde20 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -11,4 +11,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def developer sign_in_with "Developer" end + + def github + sign_in_with "GitHub" + end end \ No newline at end of file diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index cbf76cf..e8270f6 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -21,7 +21,11 @@ <%= link_to(t('application.sign_out'), destroy_user_session_path, method: :delete) %> <% else %> + <% if Rails.env.development? %> <%= link_to(t('application.sign_in'), user_developer_omniauth_authorize_path) %> + <% else %> + <%= link_to(t('application.sign_in'), user_github_omniauth_authorize_path) %> + <% end %> <% end %> <% end %> <% end %> diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000..1f99d15 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +fmujPxH4j3Pge1kfEi/+pTVW7yA6/X3pBWwuLTIRhchpJokcEie/lbUNlpGOhzGUeOaNZpdEWbB+DVh7r8VUf9FaTMZwyA8u7ipB6Kt7FxrmyqGF4Sb3N54JdREq5KetMCR209VR5URghVnTv6fWMNY/CnfmoAhIi6z40ARP//wSgSQIYlTSsIF/LWdaI9Zn6v3eJ4KSs53EeHyIUal5E67QnvPESwWLvZ6BrKh6GO67xfjAKnoWU4YK+bkFeffubRSKqbb9fAHZLiEVD0glOAeibuJzLAZZa5worvQQgJLZnS1syWCDIz4U6PN4/ZBfrxq8Y+TpBXCEu/5JWrr6ARqbQy8Qnte+IL5EYY65Z70vyI9fcpVYiyKtvUQOsOypf/UxMjahg0MSddZlAiY3+ufyA1Sw9s7BCClaaNtOCtRM/thwNRdn3kNh2S/9YuodVSu5PV/V6DDX9BSo/FZeTbntBSsFnIe5NWwyEaC7jn1zp0FXeAT1N7beUpYcIwWXl7roGATq5J+eSycSAydj5TSPpy6pe0JV--zgHjFhqIX9PMSptP--a4kSt219OHlMrnkVTQFQVA== \ No newline at end of file diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 8aa5cf9..81180b6 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -233,8 +233,15 @@ Devise.setup do |config| # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' - config.omniauth :developer, fields: [:name], uid_field: :name - + if Rails.env.development? + config.omniauth :developer, fields: [:name], uid_field: :name + end + if Rails.env.production? + config.omniauth :github, Rails.application.credentials.github[:client_id], Rails.application.credentials.github[:client_secret], scope: '' + end + if Rails.env.test? + config.omniauth :github, '', '', scope: '' + end # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or # change the failure app, you can configure them inside the config.warden block. diff --git a/config/secrets.yml.enc b/config/secrets.yml.enc deleted file mode 100644 index 23ddc61..0000000 --- a/config/secrets.yml.enc +++ /dev/null @@ -1 +0,0 @@ -aXUUhT76Uhw5fnfkwOwNP1EWppHhl8QB/N0VNzb0BNcZ+S2xsq9biPVY9OakzXj24If4KV9hYw5LJkN1xmQcwxQMJ2lqdow6fkdwFuHnjPMNZyzr7G3aaLylpamkBUaY7paUfRVjJAWJge0l2cv/fZcKuRS2B2CmjqjdTfcvxHb9R/UXM1Vv10Cp88dPKlQ11SYd3g0m6W87TZL+Hut6hweKuvA6DJlnGpNH/B+yaVYPzVfkpCN7mtNv7HEtkfATMzeoPmeW10EgwfljntfPZ33l5+eOJvOidrme1vDzVKO7Ag==--7sKcvkcMXbiQWQdA--aIz51lRbRz/t/xnkvY8WTQ== \ No newline at end of file diff --git a/test/integration/translator_flow_test.rb b/test/integration/translator_flow_test.rb new file mode 100644 index 0000000..4f32991 --- /dev/null +++ b/test/integration/translator_flow_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class TranslatorFlowTest < ActionDispatch::IntegrationTest + test "can view a problem" do + get '/problems/1' + assert_response :success + assert_select "h1", "First title Problem 1" + end + + test "can login via github" do + get '/users/auth/github' + assert_response :redirect + follow_redirect! + follow_redirect! + assert_response :success + assert controller.user_signed_in? + assert_equal "translator", controller.current_user.name + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 234ca2a..4940770 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -20,3 +20,13 @@ class ActiveSupport::TestCase sign_in translator end end + + +class ActionDispatch::IntegrationTest + OmniAuth.config.test_mode = true + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new({ + provider: :github, + uid: 'translator', + name: 'translator' + }) +end \ No newline at end of file