writing documentation & testing

parent a7a020ad
......@@ -5,4 +5,5 @@ gem 'json'
group :development, :test do
gem 'mailcatcher'
gem 'pry'
end
\ No newline at end of file
......@@ -5,6 +5,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
coderay (1.0.7)
daemons (1.1.8)
eventmachine (0.12.10)
faraday (0.7.6)
......@@ -27,6 +28,7 @@ GEM
skinny (~> 0.2, >= 0.2.1)
sqlite3 (~> 1.3)
thin (~> 1.2)
method_source (0.8)
mime-types (1.19)
multi_json (1.3.6)
multipart-post (1.1.5)
......@@ -34,6 +36,10 @@ GEM
faraday (~> 0.7)
multi_json (~> 1.0)
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-protection (1.2.0)
rack
......@@ -44,13 +50,13 @@ GEM
skinny (0.2.1)
eventmachine (~> 0.12)
thin (~> 1.2)
slop (3.3.3)
sqlite3 (1.3.6)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
tmail (1.2.7.1)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
......@@ -62,4 +68,4 @@ DEPENDENCIES
json
mailcatcher
oauth2
tmail
pry
......@@ -2,8 +2,9 @@ require 'account_controller'
require 'json'
class RedmineOauthController < AccountController
include Helpers::MailHelper
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)
else
password_authentication
......@@ -57,11 +58,6 @@ class RedmineOauthController < AccountController
end
end
def email_prefix email
prefix = email.match(/(.+?)@/) if email
prefix[1] if prefix
end
def oauth_client
@client ||= OAuth2::Client.new(settings[:client_id], settings[:client_secret],
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 %>
<% end %>
\ No newline at end of file
......@@ -5,4 +5,8 @@
<p>
<label>Client Secret:</label>
<%= text_field_tag 'settings[client_secret]', @settings[:client_secret] %>
</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
author_url 'https://tsdv.net/redmine/users/105'
settings default: {
client_id: '214698823792.apps.googleusercontent.com',
client_secret: 'M0HJPMypEgrDAKKHGiP6Y2R-' }, partial: 'settings/google_settings'
end
client_secret: 'M0HJPMypEgrDAKKHGiP6Y2R-', oauth_autentification: false}, partial: 'settings/google_settings'
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('../../../lib/helpers/mail_helper', __FILE__)
class RedmineOauthControllerTest < ActionController::TestCase
include Helpers::MailHelper
def setup
@default_user_credentials = { firstname: 'Cool',
lastname: 'User',
......@@ -30,13 +31,13 @@ class RedmineOauthControllerTest < ActionController::TestCase
OAuth2::Response.any_instance.stubs(body: @default_response_body.merge(options).to_json)
end
def test_oauth_google_with_disabled_openid
Setting.openid = false
def test_oauth_google_with_enabled_oauth_authentification
Setting.plugin_redmine_omniauth_google[:oauth_authentification] = nil
get :oauth_google
assert_redirected_to signin_path
assert_response 404
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'
user = new_user status: User::STATUS_REGISTERED
assert user.save
......@@ -45,7 +46,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
assert_redirected_to signin_path
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.activate
assert user.save
......@@ -54,7 +55,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
assert_redirected_to controller: 'my', action: 'page'
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'
set_response_body_stub
get :oauth_google_callback
......@@ -64,21 +65,38 @@ class RedmineOauthControllerTest < ActionController::TestCase
assert_equal user.login, email_prefix(@default_response_body[:email])
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'
set_response_body_stub
get :oauth_google_callback
assert_redirected_to signin_path
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'
set_response_body_stub verified_email: false
get :oauth_google_callback
assert_redirected_to signin_path
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
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment