This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate authentication engine with API engine. Added integration te…
…sts for both admin and api integrations.
- Loading branch information
1 parent
fd704fb
commit b130ba2
Showing
19 changed files
with
187 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'push_type_core' | ||
require 'push_type_api' | ||
|
||
require 'coffee-rails' | ||
require 'sass-rails' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'push_type_core' | ||
|
||
require 'jbuilder' | ||
require 'kaminari' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
auth/app/controllers/concerns/push_type/api_authentication_methods.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module PushType | ||
module ApiAuthenticationMethods | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
acts_as_token_authentication_handler_for PushType::User, as: :user | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
SimpleTokenAuthentication.configure do |config| | ||
|
||
# Configure the session persistence policy after a successful sign in, | ||
# in other words, if the authentication token acts as a signin token. | ||
# If true, user is stored in the session and the authentication token and | ||
# email may be provided only once. | ||
# If false, users must provide their authentication token and email at every request. | ||
# config.sign_in_token = false | ||
|
||
# Configure the name of the HTTP headers watched for authentication. | ||
# | ||
# Default header names for a given token authenticatable entity follow the pattern: | ||
# { entity: { authentication_token: 'X-Entity-Token', email: 'X-Entity-Email'} } | ||
# | ||
# When several token authenticatable models are defined, custom header names | ||
# can be specified for none, any, or all of them. | ||
# | ||
# Note: when using the identifiers options, this option behaviour is modified. | ||
# Please see the example below. | ||
# | ||
# Examples | ||
# | ||
# Given User and SuperAdmin are token authenticatable, | ||
# When the following configuration is used: | ||
# `config.header_names = { super_admin: { authentication_token: 'X-Admin-Auth-Token' } }` | ||
# Then the token authentification handler for User watches the following headers: | ||
# `X-User-Token, X-User-Email` | ||
# And the token authentification handler for SuperAdmin watches the following headers: | ||
# `X-Admin-Auth-Token, X-SuperAdmin-Email` | ||
# | ||
# When the identifiers option is set: | ||
# `config.identifiers = { super_admin: :phone_number }` | ||
# Then both the header names identifier key and default value are modified accordingly: | ||
# `config.header_names = { super_admin: { phone_number: 'X-SuperAdmin-PhoneNumber' } }` | ||
# | ||
# config.header_names = { user: { authentication_token: 'X-User-Token', email: 'X-User-Email' } } | ||
|
||
# Configure the name of the attribute used to identify the user for authentication. | ||
# That attribute must exist in your model. | ||
# | ||
# The default identifiers follow the pattern: | ||
# { entity: 'email' } | ||
# | ||
# Note: the identifer must match your Devise configuration, | ||
# see https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address#tell-devise-to-use-username-in-the-authentication_keys | ||
# | ||
# Note: setting this option does modify the header_names behaviour, | ||
# see the header_names section above. | ||
# | ||
# Example: | ||
# | ||
# `config.identifiers = { super_admin: 'phone_number', user: 'uuid' }` | ||
# | ||
# config.identifiers = { user: 'email' } | ||
|
||
# Configure the Devise trackable strategy integration. | ||
# | ||
# If true, tracking is disabled for token authentication: signing in through | ||
# token authentication won't modify the Devise trackable statistics. | ||
# | ||
# If false, given Devise trackable is configured for the relevant model, | ||
# then signing in through token authentication will be tracked as any other sign in. | ||
# | ||
# config.skip_devise_trackable = true | ||
end |
6 changes: 6 additions & 0 deletions
6
auth/db/migrate/20160711133742_add_authentication_token_to_push_type_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddAuthenticationTokenToPushTypeUsers < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :push_type_users, :authentication_token, :string, limit: 30 | ||
add_index :push_type_users, :authentication_token, unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
auth/test/controllers/concerns/push_type/api_authentication_methods_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'test_helper' | ||
|
||
module PushType | ||
class ApiAuthenticationMethodsTest < ActiveSupport::TestCase | ||
|
||
subject { PushType::ApiController.new } | ||
let :before_filters do | ||
subject._process_action_callbacks.find_all { |x| x.kind == :before }.map(&:filter) | ||
end | ||
|
||
it { subject.methods.include?(:authenticate_user_from_token!).must_equal true } | ||
it { before_filters.include?(:authenticate_user_from_token!).must_equal true } | ||
|
||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
auth/test/integration/push_type/authenticated_api_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'test_helper' | ||
|
||
class AuthenticatedApiControllerTest < ActionDispatch::IntegrationTest | ||
|
||
let(:current_user) { FactoryGirl.create(:confirmed_user) } | ||
|
||
describe 'unauthenticated request' do | ||
before { get api_nodes_path } | ||
it { response.must_respond_with :unauthorized } | ||
end | ||
|
||
describe 'authenticated request' do | ||
before { get api_nodes_path, headers: { 'X-User-Email' => current_user.email, 'X-User-Token' => current_user.authentication_token } } | ||
it { response.must_respond_with :success } | ||
end | ||
|
||
end |
20 changes: 20 additions & 0 deletions
20
auth/test/integration/push_type/authenticated_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'test_helper' | ||
|
||
class AuthenticatedControllerTest < ActionDispatch::IntegrationTest | ||
|
||
let(:current_user) { FactoryGirl.create(:confirmed_user, password: 'password', password_confirmation: 'password') } | ||
|
||
describe 'unauthenticated request' do | ||
before { get nodes_path } | ||
it { response.must_redirect_to new_user_session_path } | ||
end | ||
|
||
describe 'authenticated request' do | ||
before do | ||
post user_session_path, params: { user: { email: current_user.email, password: 'password' } } | ||
get nodes_path | ||
end | ||
it { response.must_respond_with :success } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters