devise-authy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +138 -0
- data/LICENSE.txt +20 -0
- data/README.md +86 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/app/assets/javascripts/devise_authy.js +7 -0
- data/app/assets/stylesheets/devise_authy.css +26 -0
- data/app/assets/stylesheets/devise_authy.sass +23 -0
- data/app/controllers/devise/devise_authy_controller.rb +109 -0
- data/app/views/devise/enable_authy.html.erb +8 -0
- data/app/views/devise/enable_authy.html.haml +8 -0
- data/app/views/devise/verify_authy.html.erb +13 -0
- data/app/views/devise/verify_authy.html.haml +11 -0
- data/app/views/devise/verify_authy_installation.html.erb +10 -0
- data/app/views/devise/verify_authy_installation.html.haml +8 -0
- data/authy-devise-demo/.gitignore +15 -0
- data/authy-devise-demo/Gemfile +39 -0
- data/authy-devise-demo/Gemfile.lock +134 -0
- data/authy-devise-demo/README.md +64 -0
- data/authy-devise-demo/Rakefile +7 -0
- data/authy-devise-demo/app/assets/images/rails.png +0 -0
- data/authy-devise-demo/app/assets/javascripts/application.js +15 -0
- data/authy-devise-demo/app/assets/javascripts/devise_authy.js +7 -0
- data/authy-devise-demo/app/assets/javascripts/welcome.js.coffee +3 -0
- data/authy-devise-demo/app/assets/stylesheets/application.css +13 -0
- data/authy-devise-demo/app/assets/stylesheets/devise_authy.css +26 -0
- data/authy-devise-demo/app/assets/stylesheets/welcome.css.scss +3 -0
- data/authy-devise-demo/app/controllers/application_controller.rb +3 -0
- data/authy-devise-demo/app/controllers/welcome_controller.rb +6 -0
- data/authy-devise-demo/app/helpers/application_helper.rb +2 -0
- data/authy-devise-demo/app/helpers/welcome_helper.rb +2 -0
- data/authy-devise-demo/app/mailers/.gitkeep +0 -0
- data/authy-devise-demo/app/models/.gitkeep +0 -0
- data/authy-devise-demo/app/models/user.rb +11 -0
- data/authy-devise-demo/app/views/devise/devise_authy/enable_authy.html.erb +8 -0
- data/authy-devise-demo/app/views/devise/devise_authy/verify_authy.html.erb +13 -0
- data/authy-devise-demo/app/views/devise/devise_authy/verify_authy_installation.html.erb +10 -0
- data/authy-devise-demo/app/views/layouts/application.html.erb +18 -0
- data/authy-devise-demo/app/views/welcome/index.html.erb +5 -0
- data/authy-devise-demo/config.ru +4 -0
- data/authy-devise-demo/config/application.rb +62 -0
- data/authy-devise-demo/config/boot.rb +6 -0
- data/authy-devise-demo/config/database.yml +25 -0
- data/authy-devise-demo/config/environment.rb +5 -0
- data/authy-devise-demo/config/environments/development.rb +37 -0
- data/authy-devise-demo/config/environments/production.rb +67 -0
- data/authy-devise-demo/config/environments/test.rb +37 -0
- data/authy-devise-demo/config/initializers/authy.rb +1 -0
- data/authy-devise-demo/config/initializers/backtrace_silencers.rb +7 -0
- data/authy-devise-demo/config/initializers/devise.rb +232 -0
- data/authy-devise-demo/config/initializers/inflections.rb +15 -0
- data/authy-devise-demo/config/initializers/mime_types.rb +5 -0
- data/authy-devise-demo/config/initializers/secret_token.rb +7 -0
- data/authy-devise-demo/config/initializers/session_store.rb +8 -0
- data/authy-devise-demo/config/initializers/wrap_parameters.rb +14 -0
- data/authy-devise-demo/config/locales/devise.authy.en.yml +18 -0
- data/authy-devise-demo/config/locales/devise.en.yml +58 -0
- data/authy-devise-demo/config/locales/en.yml +5 -0
- data/authy-devise-demo/config/routes.rb +62 -0
- data/authy-devise-demo/db/migrate/20130409234357_devise_create_users.rb +46 -0
- data/authy-devise-demo/db/migrate/20130409234434_devise_authy_add_to_users.rb +18 -0
- data/authy-devise-demo/db/schema.rb +38 -0
- data/authy-devise-demo/db/seeds.rb +7 -0
- data/authy-devise-demo/lib/assets/.gitkeep +0 -0
- data/authy-devise-demo/lib/tasks/.gitkeep +0 -0
- data/authy-devise-demo/log/.gitkeep +0 -0
- data/authy-devise-demo/public/404.html +26 -0
- data/authy-devise-demo/public/422.html +26 -0
- data/authy-devise-demo/public/500.html +25 -0
- data/authy-devise-demo/public/favicon.ico +0 -0
- data/authy-devise-demo/public/robots.txt +5 -0
- data/authy-devise-demo/script/rails +6 -0
- data/authy-devise-demo/test/fixtures/.gitkeep +0 -0
- data/authy-devise-demo/test/fixtures/users.yml +11 -0
- data/authy-devise-demo/test/functional/.gitkeep +0 -0
- data/authy-devise-demo/test/functional/welcome_controller_test.rb +9 -0
- data/authy-devise-demo/test/integration/.gitkeep +0 -0
- data/authy-devise-demo/test/performance/browsing_test.rb +12 -0
- data/authy-devise-demo/test/test_helper.rb +13 -0
- data/authy-devise-demo/test/unit/.gitkeep +0 -0
- data/authy-devise-demo/test/unit/helpers/welcome_helper_test.rb +4 -0
- data/authy-devise-demo/test/unit/user_test.rb +7 -0
- data/authy-devise-demo/vendor/assets/javascripts/.gitkeep +0 -0
- data/authy-devise-demo/vendor/assets/stylesheets/.gitkeep +0 -0
- data/authy-devise-demo/vendor/plugins/.gitkeep +0 -0
- data/config/locales/en.yml +18 -0
- data/devise-authy.gemspec +223 -0
- data/lib/devise-authy.rb +22 -0
- data/lib/devise-authy/controllers/helpers.rb +39 -0
- data/lib/devise-authy/controllers/view_helpers.rb +36 -0
- data/lib/devise-authy/hooks/authy_authenticatable.rb +7 -0
- data/lib/devise-authy/models/authy_authenticatable.rb +23 -0
- data/lib/devise-authy/rails.rb +11 -0
- data/lib/devise-authy/routes.rb +20 -0
- data/lib/devise-authy/version.rb +3 -0
- data/lib/generators/active_record/devise_authy_generator.rb +13 -0
- data/lib/generators/active_record/templates/migration.rb +18 -0
- data/lib/generators/devise_authy/devise_authy_generator.rb +30 -0
- data/lib/generators/devise_authy/install_generator.rb +64 -0
- data/spec/controllers/devise_authy_controller_spec.rb +85 -0
- data/spec/generators_spec.rb +24 -0
- data/spec/integration/authy_authenticatable.rb +88 -0
- data/spec/models/authy_authenticatable.rb +17 -0
- data/spec/orm/active_record.rb +4 -0
- data/spec/rails_app/Rakefile +10 -0
- data/spec/rails_app/app/assets/images/rails.png +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +10 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +9 -0
- data/spec/rails_app/app/assets/stylesheets/devise_authy.css +26 -0
- data/spec/rails_app/app/assets/stylesheets/devise_authy.css.scss +26 -0
- data/spec/rails_app/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/spec/rails_app/app/controllers/application_controller.rb +4 -0
- data/spec/rails_app/app/controllers/posts_controller.rb +83 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_app/app/helpers/posts_helper.rb +2 -0
- data/spec/rails_app/app/mailers/.gitkeep +0 -0
- data/spec/rails_app/app/models/.gitkeep +0 -0
- data/spec/rails_app/app/models/post.rb +2 -0
- data/spec/rails_app/app/models/user.rb +9 -0
- data/spec/rails_app/app/views/devise/devise_authy/register.html.erb +10 -0
- data/spec/rails_app/app/views/devise/devise_authy/show.html.erb +10 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +24 -0
- data/spec/rails_app/app/views/posts/_form.html.erb +25 -0
- data/spec/rails_app/app/views/posts/edit.html.erb +6 -0
- data/spec/rails_app/app/views/posts/index.html.erb +27 -0
- data/spec/rails_app/app/views/posts/new.html.erb +5 -0
- data/spec/rails_app/app/views/posts/show.html.erb +15 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +33 -0
- data/spec/rails_app/config/boot.rb +7 -0
- data/spec/rails_app/config/database.yml +22 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +37 -0
- data/spec/rails_app/config/environments/production.rb +67 -0
- data/spec/rails_app/config/environments/test.rb +37 -0
- data/spec/rails_app/config/initializers/authy.rb +3 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/devise.rb +237 -0
- data/spec/rails_app/config/initializers/inflections.rb +10 -0
- data/spec/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/rails_app/config/initializers/session_store.rb +8 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_app/config/locales/devise.authy.en.yml +14 -0
- data/spec/rails_app/config/routes.rb +6 -0
- data/spec/rails_app/db/migrate/20121029205626_devise_create_users.rb +32 -0
- data/spec/rails_app/db/migrate/20121029205627_create_posts.rb +10 -0
- data/spec/rails_app/db/migrate/20121029205628_devise_authy_add_to_users.rb +15 -0
- data/spec/rails_app/db/schema.rb +43 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/script/rails +6 -0
- data/spec/routing/routes_spec.rb +19 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/helpers.rb +28 -0
- metadata +367 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'rails/generators/active_record'
|
|
2
|
+
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module Generators
|
|
5
|
+
class DeviseAuthyGenerator < ActiveRecord::Generators::Base
|
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
7
|
+
|
|
8
|
+
def copy_devise_migration
|
|
9
|
+
migration_template "migration.rb", "db/migrate/devise_authy_add_to_#{table_name}"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class DeviseAuthyAddTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
change_table :<%= table_name %> do |t|
|
|
4
|
+
t.string :authy_id
|
|
5
|
+
t.datetime :last_sign_in_with_authy
|
|
6
|
+
t.boolean :authy_enabled, :default => false
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
add_index :<%= table_name %>, :authy_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.down
|
|
13
|
+
change_table :<%= table_name %> do |t|
|
|
14
|
+
t.remove :authy_id, :last_sign_in_with_authy, :authy_enabled
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module DeviseAuthy
|
|
2
|
+
module Generators
|
|
3
|
+
class DeviseAuthyGenerator < Rails::Generators::NamedBase
|
|
4
|
+
|
|
5
|
+
namespace "devise_authy"
|
|
6
|
+
|
|
7
|
+
desc "Add :authy_authenticatable directive in the given model, plus accessors. Also generate migration for ActiveRecord"
|
|
8
|
+
|
|
9
|
+
def inject_devise_authy_content
|
|
10
|
+
path = File.join("app","models","#{file_path}.rb")
|
|
11
|
+
if File.exists?(path) &&
|
|
12
|
+
!File.read(path).include?("authy_authenticatable")
|
|
13
|
+
inject_into_file(path,
|
|
14
|
+
"authy_authenticatable, :",
|
|
15
|
+
:after => "devise :")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
if File.exists?(path) &&
|
|
19
|
+
!File.read(path).include?(":authy_id")
|
|
20
|
+
inject_into_file(path,
|
|
21
|
+
":authy_id, :last_sign_in_with_authy, ",
|
|
22
|
+
:after => "attr_accessible ")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
hook_for :orm
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module DeviseAuthy
|
|
2
|
+
module Generators
|
|
3
|
+
# Install Generator
|
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
|
6
|
+
|
|
7
|
+
class_option :haml, :type => :boolean, :required => false, :default => false, :desc => "Generate views in Haml"
|
|
8
|
+
class_option :sass, :type => :boolean, :required => false, :default => false, :desc => "Generate stylesheet in Sass"
|
|
9
|
+
|
|
10
|
+
desc "Install the devise authy extension"
|
|
11
|
+
|
|
12
|
+
def copy_locale
|
|
13
|
+
copy_file "../../../config/locales/en.yml", "config/locales/devise.authy.en.yml"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def copy_views
|
|
17
|
+
if options.haml?
|
|
18
|
+
copy_file '../../../app/views/devise/enable_authy.html.haml', 'app/views/devise/devise_authy/enable_authy.html.haml'
|
|
19
|
+
copy_file '../../../app/views/devise/verify_authy.html.haml', 'app/views/devise/devise_authy/verify_authy.html.haml'
|
|
20
|
+
copy_file '../../../app/views/devise/verify_authy_installation.html.haml', 'app/views/devise/devise_authy/verify_authy_installation.html.haml'
|
|
21
|
+
else
|
|
22
|
+
copy_file '../../../app/views/devise/enable_authy.html.erb', 'app/views/devise/devise_authy/enable_authy.html.erb'
|
|
23
|
+
copy_file '../../../app/views/devise/verify_authy.html.erb', 'app/views/devise/devise_authy/verify_authy.html.erb'
|
|
24
|
+
copy_file '../../../app/views/devise/verify_authy_installation.html.erb', 'app/views/devise/devise_authy/verify_authy_installation.html.erb'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def copy_assets
|
|
29
|
+
if options.sass?
|
|
30
|
+
copy_file '../../../app/assets/stylesheets/devise_authy.sass', 'app/assets/stylesheets/devise_authy.sass'
|
|
31
|
+
else
|
|
32
|
+
copy_file '../../../app/assets/stylesheets/devise_authy.css', 'app/assets/stylesheets/devise_authy.css'
|
|
33
|
+
end
|
|
34
|
+
copy_file '../../../app/assets/javascripts/devise_authy.js', 'app/assets/javascripts/devise_authy.js'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def inject_assets_in_layout
|
|
38
|
+
{
|
|
39
|
+
:haml => {
|
|
40
|
+
:before => %r{%body\s*$},
|
|
41
|
+
:content => %@
|
|
42
|
+
=javascript_include_tag "https://www.authy.com/form.authy.min.js"
|
|
43
|
+
=stylesheet_link_tag "https://www.authy.com/form.authy.min.css"
|
|
44
|
+
=javascript_include_tag "devise_authy.js"
|
|
45
|
+
@
|
|
46
|
+
},
|
|
47
|
+
:erb => {
|
|
48
|
+
:before => %r{\s*</\s*head\s*>\s*},
|
|
49
|
+
:content => %@
|
|
50
|
+
<%=javascript_include_tag "https://www.authy.com/form.authy.min.js" %>
|
|
51
|
+
<%=stylesheet_link_tag "https://www.authy.com/form.authy.min.css" %>
|
|
52
|
+
<%=javascript_include_tag "devise_authy.js" %>
|
|
53
|
+
@
|
|
54
|
+
}
|
|
55
|
+
}.each do |extension, opts|
|
|
56
|
+
file_path = "app/views/layouts/application.html.#{extension}"
|
|
57
|
+
if File.exists?(file_path) && !File.read(file_path).include?("devise_authy.js")
|
|
58
|
+
inject_into_file(file_path, opts.delete(:content), opts)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Devise::DeviseAuthyController do
|
|
4
|
+
include Devise::TestHelpers
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
@user = create_user(:authy_id => '80')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "GET #show" do
|
|
11
|
+
it "Should render the second step of authentication" do
|
|
12
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
13
|
+
get :show
|
|
14
|
+
response.should render_template('show')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "PUT #update" do
|
|
19
|
+
it "Should login the user if token is ok" do
|
|
20
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
21
|
+
response = mock("authy_request", body: {'status' => 'ok'}.to_json)
|
|
22
|
+
response.stub(:ok?).and_return(true)
|
|
23
|
+
Authy::API.should_receive(:verify).with(:id => '80', :token => '567890').and_return(response)
|
|
24
|
+
|
|
25
|
+
put :update, :user => {
|
|
26
|
+
:authy_id => '80',
|
|
27
|
+
:token => '567890'
|
|
28
|
+
}
|
|
29
|
+
response.should redirect_to(root_url)
|
|
30
|
+
flash.now[:notice].should_not be_nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "Shouldn't login the user if token is invalid" do
|
|
34
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
35
|
+
response = mock("authy_request", body: {"errors"=>{"token"=>"is invalid"}}.to_json)
|
|
36
|
+
response.stub(:ok?).and_return(false)
|
|
37
|
+
Authy::API.should_receive(:verify).with(:id => '80', :token => '567890').and_return(response)
|
|
38
|
+
put :update, :user => {
|
|
39
|
+
:authy_id => '80',
|
|
40
|
+
:token => '567890'
|
|
41
|
+
}
|
|
42
|
+
response.should redirect_to(root_url)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "GET #register" do
|
|
47
|
+
it "Should render enable authy view" do
|
|
48
|
+
sign_in @user
|
|
49
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
50
|
+
get :register
|
|
51
|
+
response.should render_template('register')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "Shouldn't render enable authy view" do
|
|
55
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
56
|
+
get :register
|
|
57
|
+
response.should redirect_to(new_user_session_url)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "POST #create" do
|
|
62
|
+
it "Should create user in authy application" do
|
|
63
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
64
|
+
sign_in @user
|
|
65
|
+
response = mock("authy_request", body: {'success' => 'ok'}.to_json)
|
|
66
|
+
response.should_receive(:ok?).and_return(true)
|
|
67
|
+
response.should_receive(:id).and_return('99')
|
|
68
|
+
Authy::API.should_receive(:register_user).with(:email => @user.email, :cellphone => '3010008090', :country_code => '57').and_return(response)
|
|
69
|
+
|
|
70
|
+
post :create, :cellphone => '3010008090', :country_code => '57'
|
|
71
|
+
|
|
72
|
+
flash.now[:notice].should_not be_nil
|
|
73
|
+
response.should redirect_to(root_url)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "Should redirect if user isn't authenticated" do
|
|
77
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
78
|
+
post :create, :user => {
|
|
79
|
+
:cellphone => '3010008090',
|
|
80
|
+
:country_code => '57'
|
|
81
|
+
}
|
|
82
|
+
response.should redirect_to(new_user_session_url)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
|
4
|
+
require 'rails/generators'
|
|
5
|
+
require 'generators/devise_authy/devise_authy_generator'
|
|
6
|
+
|
|
7
|
+
describe "generators for devise_authy" do
|
|
8
|
+
RAILS_APP_PATH = File.expand_path("../rails_app", __FILE__)
|
|
9
|
+
|
|
10
|
+
it "rails g should include the generators" do
|
|
11
|
+
@output = `cd #{RAILS_APP_PATH} && rails g`
|
|
12
|
+
@output.include?('devise_authy:install').should be_true
|
|
13
|
+
@output.include?('active_record:devise_authy').should be_true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "rails g devise_authy:install" do
|
|
17
|
+
@output = `cd #{RAILS_APP_PATH} && rails g devise_authy:install -p`
|
|
18
|
+
@output.include?('config/initializers/devise.rb').should be_true
|
|
19
|
+
@output.include?('config/locales/devise.authy.en.yml').should be_true
|
|
20
|
+
@output.include?('app/views/devise/devise_authy/register.html.erb').should be_true
|
|
21
|
+
@output.include?('app/views/devise/devise_authy/show.html.erb').should be_true
|
|
22
|
+
@output.include?('app/assets/stylesheets/devise_authy.css').should be_true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Authy Autnenticatable", :type => :request do
|
|
4
|
+
describe "If user don't have two factor authentication should login with email - password" do
|
|
5
|
+
before :each do
|
|
6
|
+
@user = create_user(:email => 'foo@bar.com')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "Sign in should succeed" do
|
|
10
|
+
fill_sign_in_form('foo@bar.com', '12345678')
|
|
11
|
+
current_path.should == root_path
|
|
12
|
+
page.should have_content('Signed in successfully.')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "Sign in shouldn't success" do
|
|
16
|
+
fill_sign_in_form('foo@bar.com', '14567823')
|
|
17
|
+
current_path.should == new_user_session_path
|
|
18
|
+
page.should_not have_content('Signed in successfully.')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "If user have two factor authentication" do
|
|
23
|
+
before :each do
|
|
24
|
+
@user = create_user(:authy_id => '90')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "Without cookie['authy_authentication']" do
|
|
28
|
+
it "Sign in should succeed" do
|
|
29
|
+
authy_response = mock('authy_response', :ok? => true)
|
|
30
|
+
Authy::API.should_receive(:verify).with(:id => '90', :token => '324567').and_return(authy_response)
|
|
31
|
+
|
|
32
|
+
visit new_user_session_path
|
|
33
|
+
fill_sign_in_form(@user.email, '12345678')
|
|
34
|
+
current_path.should == user_devise_authy_path
|
|
35
|
+
page.should have_content('Please enter your Authy token')
|
|
36
|
+
|
|
37
|
+
within('#devise_authy') do
|
|
38
|
+
fill_in 'authy-token', :with => '324567'
|
|
39
|
+
end
|
|
40
|
+
click_on 'Check Token'
|
|
41
|
+
current_path.should == root_path
|
|
42
|
+
page.should have_content(I18n.t('devise.devise_authy.user.signed_in'))
|
|
43
|
+
@user.reload
|
|
44
|
+
@user.last_sign_in_with_authy.should_not be_nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "Sign in shouldn't success" do
|
|
48
|
+
authy_response = mock('authy_response', :ok? => false)
|
|
49
|
+
Authy::API.should_receive(:verify).with(:id => '90', :token => '324567').and_return(authy_response)
|
|
50
|
+
|
|
51
|
+
visit new_user_session_path
|
|
52
|
+
fill_sign_in_form(@user.email, '12345678')
|
|
53
|
+
current_path.should == user_devise_authy_path
|
|
54
|
+
page.should have_content('Please enter your Authy token')
|
|
55
|
+
|
|
56
|
+
within('#devise_authy') do
|
|
57
|
+
fill_in 'authy-token', :with => '324567'
|
|
58
|
+
end
|
|
59
|
+
click_on 'Check Token'
|
|
60
|
+
current_path.should == new_user_session_path
|
|
61
|
+
@user.reload
|
|
62
|
+
@user.last_sign_in_with_authy.should be_nil
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "With cookie['authy_authentication'] and last_sign_in_with_authy less than one month shouldn't show the request token view" do
|
|
67
|
+
page.driver.browser.set_cookie('authy_authentication=true')
|
|
68
|
+
@user.last_sign_in_with_authy = 2.days.ago
|
|
69
|
+
@user.save
|
|
70
|
+
@user.reload
|
|
71
|
+
|
|
72
|
+
visit new_user_session_path
|
|
73
|
+
fill_sign_in_form(@user.email, '12345678')
|
|
74
|
+
current_path.should == root_path
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "With cookie['authy_authentication'] and last_sign_in_with_authy greater than one month should Show the request token view" do
|
|
78
|
+
page.driver.browser.set_cookie('authy_authentication=true')
|
|
79
|
+
@user.last_sign_in_with_authy = 2.months.ago
|
|
80
|
+
@user.save
|
|
81
|
+
@user.reload
|
|
82
|
+
|
|
83
|
+
visit new_user_session_path
|
|
84
|
+
fill_sign_in_form(@user.email, '12345678')
|
|
85
|
+
current_path.should == user_devise_authy_path
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Devise::Models::AuthyAuthenticatable do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@user = create_user(:authy_id => '20')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe "User#find_by_authy_id" do
|
|
9
|
+
it "Should find the user" do
|
|
10
|
+
User.find_by_authy_id('20').should_not be_nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "Shouldn't find the user" do
|
|
14
|
+
User.find_by_authy_id('80').should be_nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
|
5
|
+
|
|
6
|
+
require 'rake'
|
|
7
|
+
require 'rake/testtask'
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
|
|
10
|
+
Rails.application.load_tasks
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
|
+
// the compiled file.
|
|
6
|
+
//
|
|
7
|
+
//= require jquery
|
|
8
|
+
//= require jquery_ujs
|
|
9
|
+
//= require form.authy
|
|
10
|
+
//= require_tree .
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
|
5
|
+
*= require_self
|
|
6
|
+
*= require_tree .
|
|
7
|
+
*= require 'flags.authy'
|
|
8
|
+
*= require 'form.authy'
|
|
9
|
+
*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.devise_authy {
|
|
2
|
+
margin-left: auto;
|
|
3
|
+
margin-right: auto;
|
|
4
|
+
width: 350px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
legend {
|
|
8
|
+
display: block;
|
|
9
|
+
width: 100%;
|
|
10
|
+
padding: 0;
|
|
11
|
+
margin-bottom: 20px;
|
|
12
|
+
font-size: 21px;
|
|
13
|
+
line-height: 40px;
|
|
14
|
+
color: #333;
|
|
15
|
+
border-bottom: 1px solid #E5E5E5;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
label,
|
|
19
|
+
input,
|
|
20
|
+
button {
|
|
21
|
+
font-size: 14px;
|
|
22
|
+
font-weight: normal;
|
|
23
|
+
line-height: 20px;
|
|
24
|
+
padding: 8px;
|
|
25
|
+
margin: 8px;
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.devise_authy {
|
|
2
|
+
margin-left: auto;
|
|
3
|
+
margin-right: auto;
|
|
4
|
+
width: 350px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
legend {
|
|
8
|
+
display: block;
|
|
9
|
+
width: 100%;
|
|
10
|
+
padding: 0;
|
|
11
|
+
margin-bottom: 20px;
|
|
12
|
+
font-size: 21px;
|
|
13
|
+
line-height: 40px;
|
|
14
|
+
color: #333;
|
|
15
|
+
border-bottom: 1px solid #E5E5E5;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
label,
|
|
19
|
+
input[type="submit"],
|
|
20
|
+
button {
|
|
21
|
+
font-size: 14px;
|
|
22
|
+
font-weight: normal;
|
|
23
|
+
line-height: 20px;
|
|
24
|
+
padding: 8px;
|
|
25
|
+
margin: 8px;
|
|
26
|
+
}
|