Skip to content
Snippets Groups Projects
Commit ac958522 authored by Дмитрий Коваленок's avatar Дмитрий Коваленок
Browse files

writing documentation & testing

parent a7a020ad
No related branches found
No related tags found
No related merge requests found
...@@ -5,4 +5,5 @@ gem 'json' ...@@ -5,4 +5,5 @@ gem 'json'
group :development, :test do group :development, :test do
gem 'mailcatcher' gem 'mailcatcher'
gem 'pry'
end end
\ No newline at end of file
...@@ -5,6 +5,7 @@ GEM ...@@ -5,6 +5,7 @@ GEM
i18n (~> 0.6) i18n (~> 0.6)
multi_json (~> 1.0) multi_json (~> 1.0)
addressable (2.3.2) addressable (2.3.2)
coderay (1.0.7)
daemons (1.1.8) daemons (1.1.8)
eventmachine (0.12.10) eventmachine (0.12.10)
faraday (0.7.6) faraday (0.7.6)
...@@ -27,6 +28,7 @@ GEM ...@@ -27,6 +28,7 @@ GEM
skinny (~> 0.2, >= 0.2.1) skinny (~> 0.2, >= 0.2.1)
sqlite3 (~> 1.3) sqlite3 (~> 1.3)
thin (~> 1.2) thin (~> 1.2)
method_source (0.8)
mime-types (1.19) mime-types (1.19)
multi_json (1.3.6) multi_json (1.3.6)
multipart-post (1.1.5) multipart-post (1.1.5)
...@@ -34,6 +36,10 @@ GEM ...@@ -34,6 +36,10 @@ GEM
faraday (~> 0.7) faraday (~> 0.7)
multi_json (~> 1.0) multi_json (~> 1.0)
polyglot (0.3.3) polyglot (0.3.3)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
rack (1.4.1) rack (1.4.1)
rack-protection (1.2.0) rack-protection (1.2.0)
rack rack
...@@ -44,13 +50,13 @@ GEM ...@@ -44,13 +50,13 @@ GEM
skinny (0.2.1) skinny (0.2.1)
eventmachine (~> 0.12) eventmachine (~> 0.12)
thin (~> 1.2) thin (~> 1.2)
slop (3.3.3)
sqlite3 (1.3.6) sqlite3 (1.3.6)
thin (1.3.1) thin (1.3.1)
daemons (>= 1.0.9) daemons (>= 1.0.9)
eventmachine (>= 0.12.6) eventmachine (>= 0.12.6)
rack (>= 1.0.0) rack (>= 1.0.0)
tilt (1.3.3) tilt (1.3.3)
tmail (1.2.7.1)
treetop (1.4.12) treetop (1.4.12)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
...@@ -62,4 +68,4 @@ DEPENDENCIES ...@@ -62,4 +68,4 @@ DEPENDENCIES
json json
mailcatcher mailcatcher
oauth2 oauth2
tmail pry
...@@ -2,8 +2,9 @@ require 'account_controller' ...@@ -2,8 +2,9 @@ require 'account_controller'
require 'json' require 'json'
class RedmineOauthController < AccountController class RedmineOauthController < AccountController
include Helpers::MailHelper
def oauth_google def oauth_google
if Setting.openid? if Setting.plugin_redmine_omniauth_google[:oauth_authentification]
redirect_to oauth_client.auth_code.authorize_url(redirect_uri: oauth_google_callback_url, scope: scopes) redirect_to oauth_client.auth_code.authorize_url(redirect_uri: oauth_google_callback_url, scope: scopes)
else else
password_authentication password_authentication
...@@ -57,11 +58,6 @@ class RedmineOauthController < AccountController ...@@ -57,11 +58,6 @@ class RedmineOauthController < AccountController
end end
end end
def email_prefix email
prefix = email.match(/(.+?)@/) if email
prefix[1] if prefix
end
def oauth_client def oauth_client
@client ||= OAuth2::Client.new(settings[:client_id], settings[:client_secret], @client ||= OAuth2::Client.new(settings[:client_id], settings[:client_secret],
site: 'https://accounts.google.com', site: 'https://accounts.google.com',
......
<% if Setting.openid? %> <% if Setting.plugin_redmine_omniauth_google[:oauth_authentification] %>
<%= link_to image_tag('/plugin_assets/redmine_omniauth_google/images/google_login_icon.jpg'), oauth_google_path %> <%= link_to image_tag('/plugin_assets/redmine_omniauth_google/images/google_login_icon.jpg'), oauth_google_path %>
<% end %> <% end %>
\ No newline at end of file
...@@ -6,3 +6,7 @@ ...@@ -6,3 +6,7 @@
<label>Client Secret:</label> <label>Client Secret:</label>
<%= text_field_tag 'settings[client_secret]', @settings[:client_secret] %> <%= text_field_tag 'settings[client_secret]', @settings[:client_secret] %>
</p> </p>
<p>
<label>Oauth authentification:</label>
<%= check_box_tag "settings[oauth_authentification]", true, @settings[:oauth_authentification] %>
</p>
\ No newline at end of file
...@@ -10,5 +10,5 @@ Redmine::Plugin.register :redmine_omniauth_google do ...@@ -10,5 +10,5 @@ Redmine::Plugin.register :redmine_omniauth_google do
author_url 'https://tsdv.net/redmine/users/105' author_url 'https://tsdv.net/redmine/users/105'
settings default: { settings default: {
client_id: '214698823792.apps.googleusercontent.com', client_id: '214698823792.apps.googleusercontent.com',
client_secret: 'M0HJPMypEgrDAKKHGiP6Y2R-' }, partial: 'settings/google_settings' client_secret: 'M0HJPMypEgrDAKKHGiP6Y2R-', oauth_autentification: false}, partial: 'settings/google_settings'
end end
\ No newline at end of file
module Helpers
module MailHelper
def email_prefix email
prefix = email.match(/(.+?)@/) if email
prefix[1] if prefix
end
end
end
\ No newline at end of file
require File.expand_path('../../test_helper', __FILE__) require File.expand_path('../../test_helper', __FILE__)
#require File.expand_path('../../../lib/helpers/mail_helper', __FILE__)
class RedmineOauthControllerTest < ActionController::TestCase class RedmineOauthControllerTest < ActionController::TestCase
include Helpers::MailHelper
def setup def setup
@default_user_credentials = { firstname: 'Cool', @default_user_credentials = { firstname: 'Cool',
lastname: 'User', lastname: 'User',
...@@ -30,13 +31,13 @@ class RedmineOauthControllerTest < ActionController::TestCase ...@@ -30,13 +31,13 @@ class RedmineOauthControllerTest < ActionController::TestCase
OAuth2::Response.any_instance.stubs(body: @default_response_body.merge(options).to_json) OAuth2::Response.any_instance.stubs(body: @default_response_body.merge(options).to_json)
end end
def test_oauth_google_with_disabled_openid def test_oauth_google_with_enabled_oauth_authentification
Setting.openid = false Setting.plugin_redmine_omniauth_google[:oauth_authentification] = nil
get :oauth_google get :oauth_google
assert_redirected_to signin_path assert_response 404
end end
def test_oauth_google_callback_with_oauth_for_existing_non_active_user def test_oauth_google_callback_for_existing_non_active_user
Setting.self_registration = '2' Setting.self_registration = '2'
user = new_user status: User::STATUS_REGISTERED user = new_user status: User::STATUS_REGISTERED
assert user.save assert user.save
...@@ -45,7 +46,7 @@ class RedmineOauthControllerTest < ActionController::TestCase ...@@ -45,7 +46,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
assert_redirected_to signin_path assert_redirected_to signin_path
end end
def test_oauth_google_callback_with_oauth_for_existing_active_user def test_oauth_google_callback_for_existing_active_user
user = new_user user = new_user
user.activate user.activate
assert user.save assert user.save
...@@ -54,7 +55,7 @@ class RedmineOauthControllerTest < ActionController::TestCase ...@@ -54,7 +55,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
assert_redirected_to controller: 'my', action: 'page' assert_redirected_to controller: 'my', action: 'page'
end end
def test_oauth_google_callback_with_omniauth_for_new_user_with_valid_credentials_and_sefregistration_enabled def test_oauth_google_callback_for_new_user_with_valid_credentials_and_sefregistration_enabled
Setting.self_registration = '3' Setting.self_registration = '3'
set_response_body_stub set_response_body_stub
get :oauth_google_callback get :oauth_google_callback
...@@ -64,21 +65,38 @@ class RedmineOauthControllerTest < ActionController::TestCase ...@@ -64,21 +65,38 @@ class RedmineOauthControllerTest < ActionController::TestCase
assert_equal user.login, email_prefix(@default_response_body[:email]) assert_equal user.login, email_prefix(@default_response_body[:email])
end end
def test_oauth_google_callback_with_omniauth_for_new_user_with_valid_credentials_and_sefregistration_disabled def test_oauth_google_callback_for_new_user_with_valid_credentials_and_sefregistration_disabled
Setting.self_registration = '2' Setting.self_registration = '2'
set_response_body_stub set_response_body_stub
get :oauth_google_callback get :oauth_google_callback
assert_redirected_to signin_path assert_redirected_to signin_path
end end
def test_oauth_google_callback_with_oauth_for_new_user_with_invalid_oauth_provider def test_oauth_google_callback_with_new_user_with_invalid_oauth_provider
Setting.self_registration = '3' Setting.self_registration = '3'
set_response_body_stub verified_email: false set_response_body_stub verified_email: false
get :oauth_google_callback get :oauth_google_callback
assert_redirected_to signin_path assert_redirected_to signin_path
end end
#def test_login_with def test_oauth_google_callback_with_new_user_created_with_email_activation_should_have_a_token
Setting.self_registration = '1'
set_response_body_stub
get :oauth_google_callback
assert_redirected_to :signin
user = User.find_by_mail(@default_user_credentials[:mail])
assert user
token = Token.find_by_user_id_and_action(user.id, 'register')
assert token
end
#assert existing_user.save! def test_oauth_google_callback_with_new_user_created_with_manual_activation
Setting.self_registration = '2'
set_response_body_stub
get :oauth_google_callback
assert_redirected_to :signin
user = User.find_by_mail(@default_user_credentials[:mail])
assert user
assert_equal User::STATUS_REGISTERED, user.status
end
end end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment