wordjelly-auth 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/auth/version.rb +1 -1
- data/spec/auth_test.rb +7 -0
- data/spec/controllers/auth/admin_create_users_controller_spec.rb +141 -0
- data/spec/controllers/auth/clients_controller_spec.rb +223 -0
- data/spec/controllers/auth/search_controller_spec.rb +5 -0
- data/spec/controllers/auth/shopping/discounts_controller_spec.rb +54 -0
- data/spec/controllers/auth/users/profiles_controller_spec.rb +5 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/activity.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/javascripts/home.js +2 -0
- data/spec/dummy/app/assets/javascripts/pollymer.min.js +170 -0
- data/spec/dummy/app/assets/javascripts/tests.js +2 -0
- data/spec/dummy/app/assets/javascripts/topics.js +2 -0
- data/spec/dummy/app/assets/stylesheets/activity.css +4 -0
- data/spec/dummy/app/assets/stylesheets/application.scss +16 -0
- data/spec/dummy/app/assets/stylesheets/home.css +4 -0
- data/spec/dummy/app/assets/stylesheets/tests.css +4 -0
- data/spec/dummy/app/assets/stylesheets/topics.css +4 -0
- data/spec/dummy/app/controllers/activity_controller.rb +3 -0
- data/spec/dummy/app/controllers/admins/confirmations_controller.rb +28 -0
- data/spec/dummy/app/controllers/admins/omniauth_callbacks_controller.rb +28 -0
- data/spec/dummy/app/controllers/admins/passwords_controller.rb +32 -0
- data/spec/dummy/app/controllers/admins/registrations_controller.rb +60 -0
- data/spec/dummy/app/controllers/admins/sessions_controller.rb +5 -0
- data/spec/dummy/app/controllers/admins/unlocks_controller.rb +28 -0
- data/spec/dummy/app/controllers/application_controller.rb +49 -0
- data/spec/dummy/app/controllers/home_controller.rb +13 -0
- data/spec/dummy/app/controllers/otp_controller.rb +3 -0
- data/spec/dummy/app/controllers/shopping/cart_items_controller.rb +28 -0
- data/spec/dummy/app/controllers/shopping/carts_controller.rb +4 -0
- data/spec/dummy/app/controllers/shopping/discounts_controller.rb +3 -0
- data/spec/dummy/app/controllers/shopping/payments_controller.rb +5 -0
- data/spec/dummy/app/controllers/shopping/products_controller.rb +2 -0
- data/spec/dummy/app/controllers/tests_controller.rb +58 -0
- data/spec/dummy/app/controllers/topics_controller.rb +63 -0
- data/spec/dummy/app/controllers/users/sessions_controller.rb +3 -0
- data/spec/dummy/app/controllers/webhooks_controller.rb +13 -0
- data/spec/dummy/app/helpers/activity_helper.rb +2 -0
- data/spec/dummy/app/helpers/api/v1/token_auth_helper.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/home_helper.rb +2 -0
- data/spec/dummy/app/helpers/tests_helper.rb +2 -0
- data/spec/dummy/app/helpers/topics_helper.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/mailers/new.rb +3 -0
- data/spec/dummy/app/models/activity.rb +3 -0
- data/spec/dummy/app/models/admin.rb +12 -0
- data/spec/dummy/app/models/noti.rb +48 -0
- data/spec/dummy/app/models/noti_response.rb +9 -0
- data/spec/dummy/app/models/shopping/cart.rb +3 -0
- data/spec/dummy/app/models/shopping/cart_item.rb +7 -0
- data/spec/dummy/app/models/shopping/discount.rb +3 -0
- data/spec/dummy/app/models/shopping/payment.rb +16 -0
- data/spec/dummy/app/models/shopping/product.rb +6 -0
- data/spec/dummy/app/models/test.rb +5 -0
- data/spec/dummy/app/models/topic.rb +75 -0
- data/spec/dummy/app/models/user.rb +95 -0
- data/spec/dummy/app/views/home/index.html.erb +6 -0
- data/spec/dummy/app/views/home/send_notification.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +26 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +8 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/app/views/new/notification.html.erb +1 -0
- data/spec/dummy/app/views/new/notification.text.erb +1 -0
- data/spec/dummy/app/views/shopping/_navigation_options.html.erb +1 -0
- data/spec/dummy/app/views/tests/_form.html.erb +25 -0
- data/spec/dummy/app/views/tests/edit.html.erb +6 -0
- data/spec/dummy/app/views/tests/index.html.erb +33 -0
- data/spec/dummy/app/views/tests/new.html.erb +5 -0
- data/spec/dummy/app/views/tests/show.html.erb +14 -0
- data/spec/dummy/app/views/topics/_form.html.erb +25 -0
- data/spec/dummy/app/views/topics/edit.html.erb +6 -0
- data/spec/dummy/app/views/topics/index.html.erb +29 -0
- data/spec/dummy/app/views/topics/new.html.erb +5 -0
- data/spec/dummy/app/views/topics/show.html.erb +14 -0
- data/spec/dummy/app/views/users/sessions/create.js.erb +6 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +8 -0
- data/spec/dummy/config/application.rb +31 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +4 -0
- data/spec/dummy/config/environments/development.rb +57 -0
- data/spec/dummy/config/environments/production.rb +92 -0
- data/spec/dummy/config/environments/test.rb +44 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/aws.rb +15 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/devise.rb +273 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/preinitializer.rb +167 -0
- data/spec/dummy/config/initializers/redis.rb +9 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/devise.en.yml +62 -0
- data/spec/dummy/config/locales/en.yml +25 -0
- data/spec/dummy/config/mongoid.yml +142 -0
- data/spec/dummy/config/redis.yml +14 -0
- data/spec/dummy/config/routes.rb +38 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/seeds.rb +48 -0
- data/spec/dummy/lib/admin/parameter_sanitizer.rb +9 -0
- data/spec/dummy/lib/assets/files/test_names.json +1 -0
- data/spec/dummy/lib/user/parameter_sanitizer.rb +8 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/shoryuken.yml +5 -0
- data/spec/dummy/sidekiq.yml +9 -0
- data/spec/dummy/sidekiq_prep.sh +6 -0
- data/spec/dummy/spec/controllers/activity_controller_spec.rb +5 -0
- data/spec/dummy/spec/controllers/tests_controller_spec.rb +141 -0
- data/spec/dummy/spec/factories/tests.rb +6 -0
- data/spec/dummy/spec/fixtures/new/send_notification +3 -0
- data/spec/dummy/spec/helpers/activity_helper_spec.rb +15 -0
- data/spec/dummy/spec/helpers/tests_helper_spec.rb +15 -0
- data/spec/dummy/spec/mailers/new_spec.rb +18 -0
- data/spec/dummy/spec/mailers/previews/new_preview.rb +13 -0
- data/spec/dummy/spec/models/test_spec.rb +5 -0
- data/spec/dummy/spec/requests/tests_spec.rb +10 -0
- data/spec/dummy/spec/routing/tests_routing_spec.rb +39 -0
- data/spec/dummy/spec/views/tests/edit.html.erb_spec.rb +21 -0
- data/spec/dummy/spec/views/tests/index.html.erb_spec.rb +22 -0
- data/spec/dummy/spec/views/tests/new.html.erb_spec.rb +21 -0
- data/spec/dummy/spec/views/tests/show.html.erb_spec.rb +16 -0
- data/spec/dummy/test/controllers/api/v1/token_auth_controller_test.rb +7 -0
- data/spec/dummy/test/controllers/home_controller_test.rb +9 -0
- data/spec/dummy/test/controllers/oauth_tests_controller_test.rb +7 -0
- data/spec/dummy/test/fixtures/oauth_tests.yml +11 -0
- data/spec/dummy/test/fixtures/users.yml +7 -0
- data/spec/dummy/test/models/oauth_test_test.rb +7 -0
- data/spec/dummy/test/models/user_test.rb +7 -0
- data/spec/factories/client_factory.rb +77 -0
- data/spec/features/additional_login_param_feature_spec.rb +63 -0
- data/spec/features/extension_spec.rb +680 -0
- data/spec/features/redirect_disable_spec.rb +74 -0
- data/spec/fixtures/auth/clients.yml +13 -0
- data/spec/helpers/auth/admin_create_users_helper_spec.rb +15 -0
- data/spec/helpers/auth/resource_helper_spec.rb +15 -0
- data/spec/helpers/auth/search_helper_spec.rb +15 -0
- data/spec/helpers/auth/users/profiles_helper_spec.rb +15 -0
- data/spec/integration/navigation_test.rb +8 -0
- data/spec/mailers/auth/notifier_spec.rb +5 -0
- data/spec/mailers/previews/auth/notifier_preview.rb +4 -0
- data/spec/models/auth/admin_create_user_spec.rb +5 -0
- data/spec/models/auth/client_test.rb +9 -0
- data/spec/models/auth/shopping/discount_spec.rb +5 -0
- data/spec/rails_helper.rb +70 -0
- data/spec/requests/admin/confirmation_request_spec.rb +164 -0
- data/spec/requests/admin/password_request_spec.rb +191 -0
- data/spec/requests/admin/registration_request_spec.rb +574 -0
- data/spec/requests/admin/session_request_spec.rb +352 -0
- data/spec/requests/admin/unlock_request_spec.rb +178 -0
- data/spec/requests/admin_create_user_request_spec.rb +303 -0
- data/spec/requests/background_job_request_spec.rb +28 -0
- data/spec/requests/cart_item_request_spec.rb +381 -0
- data/spec/requests/cart_request_spec.rb +451 -0
- data/spec/requests/client_request_spec.rb +65 -0
- data/spec/requests/discount_request_spec.rb +589 -0
- data/spec/requests/payment_request_spec.rb +1254 -0
- data/spec/requests/search_request_spec.rb +173 -0
- data/spec/requests/topic_request_spec.rb +138 -0
- data/spec/requests/user/additional_login_param_and_email_validation_spec.rb +673 -0
- data/spec/requests/user/confirmation_request_spec.rb +189 -0
- data/spec/requests/user/omniauth_callbacks_request_spec.rb +682 -0
- data/spec/requests/user/otp_basic_flow_request_spec.rb +512 -0
- data/spec/requests/user/password_request_spec.rb +216 -0
- data/spec/requests/user/registration_request_spec.rb +615 -0
- data/spec/requests/user/session_request_spec.rb +361 -0
- data/spec/requests/user/unlock_request_spec.rb +208 -0
- data/spec/routing/admin/admin_routes_spec.rb +15 -0
- data/spec/routing/auth/admin_create_users_routing_spec.rb +39 -0
- data/spec/routing/clients_controller_routes_spec.rb +75 -0
- data/spec/routing/engine_routes_spec.rb +16 -0
- data/spec/spec_helper.rb +138 -0
- data/spec/support/factory_girl.rb +3 -0
- data/spec/support/omniauth_macros.rb +195 -0
- data/spec/support/payumoney_support.rb +11 -0
- data/spec/support/sign_in_support.rb +361 -0
- data/spec/support/wait_for_ajax.rb +11 -0
- data/spec/views/auth/admin_create_users/edit.html.erb_spec.rb +14 -0
- data/spec/views/auth/admin_create_users/index.html.erb_spec.rb +14 -0
- data/spec/views/auth/admin_create_users/new.html.erb_spec.rb +14 -0
- data/spec/views/auth/admin_create_users/show.html.erb_spec.rb +11 -0
- data/spec/views/auth/shopping/discounts/create.html.erb_spec.rb +5 -0
- data/spec/views/auth/shopping/discounts/destroy.html.erb_spec.rb +5 -0
- data/spec/views/auth/shopping/discounts/edit.html.erb_spec.rb +5 -0
- data/spec/views/auth/shopping/discounts/index.html.erb_spec.rb +5 -0
- data/spec/views/auth/shopping/discounts/new.html.erb_spec.rb +5 -0
- data/spec/views/auth/shopping/discounts/show.html.erb_spec.rb +5 -0
- data/spec/views/auth/shopping/discounts/update.html.erb_spec.rb +5 -0
- data/spec/views/profile/show.html.erb_spec.rb +5 -0
- metadata +401 -3
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the ActivityHelper. For example:
|
5
|
+
#
|
6
|
+
# describe ActivityHelper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# expect(helper.concat_strings("this","that")).to eq("this that")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
RSpec.describe ActivityHelper, type: :helper do
|
14
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the TestsHelper. For example:
|
5
|
+
#
|
6
|
+
# describe TestsHelper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# expect(helper.concat_strings("this","that")).to eq("this that")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
RSpec.describe TestsHelper, type: :helper do
|
14
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe New, type: :mailer do
|
4
|
+
describe "send_notification" do
|
5
|
+
let(:mail) { New.send_notification }
|
6
|
+
|
7
|
+
it "renders the headers" do
|
8
|
+
expect(mail.subject).to eq("Send notification")
|
9
|
+
expect(mail.to).to eq(["to@example.org"])
|
10
|
+
expect(mail.from).to eq(["from@example.com"])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "renders the body" do
|
14
|
+
expect(mail.body.encoded).to match("Hi")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Preview all emails at http://localhost:3000/rails/mailers/new
|
2
|
+
class NewPreview < ActionMailer::Preview
|
3
|
+
|
4
|
+
# Preview this email at http://localhost:3000/rails/mailers/new/send_notification
|
5
|
+
def notification
|
6
|
+
u = User.new
|
7
|
+
u.email = "bhargav.r.raut@gmail.com"
|
8
|
+
n = Noti.new
|
9
|
+
n.email_subject = "notification subject set from preview."
|
10
|
+
New.notification(u,n)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe TestsController, type: :routing do
|
4
|
+
describe "routing" do
|
5
|
+
|
6
|
+
it "routes to #index" do
|
7
|
+
expect(:get => "/tests").to route_to("tests#index")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "routes to #new" do
|
11
|
+
expect(:get => "/tests/new").to route_to("tests#new")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "routes to #show" do
|
15
|
+
expect(:get => "/tests/1").to route_to("tests#show", :id => "1")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "routes to #edit" do
|
19
|
+
expect(:get => "/tests/1/edit").to route_to("tests#edit", :id => "1")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "routes to #create" do
|
23
|
+
expect(:post => "/tests").to route_to("tests#create")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "routes to #update via PUT" do
|
27
|
+
expect(:put => "/tests/1").to route_to("tests#update", :id => "1")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "routes to #update via PATCH" do
|
31
|
+
expect(:patch => "/tests/1").to route_to("tests#update", :id => "1")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "routes to #destroy" do
|
35
|
+
expect(:delete => "/tests/1").to route_to("tests#destroy", :id => "1")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "tests/edit", type: :view do
|
4
|
+
before(:each) do
|
5
|
+
@test = assign(:test, Test.create!(
|
6
|
+
:price => 1.5,
|
7
|
+
:name => "MyText"
|
8
|
+
))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "renders the edit test form" do
|
12
|
+
render
|
13
|
+
|
14
|
+
assert_select "form[action=?][method=?]", test_path(@test), "post" do
|
15
|
+
|
16
|
+
assert_select "input#test_price[name=?]", "test[price]"
|
17
|
+
|
18
|
+
assert_select "textarea#test_name[name=?]", "test[name]"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "tests/index", type: :view do
|
4
|
+
before(:each) do
|
5
|
+
assign(:tests, [
|
6
|
+
Test.create!(
|
7
|
+
:price => 2.5,
|
8
|
+
:name => "MyText"
|
9
|
+
),
|
10
|
+
Test.create!(
|
11
|
+
:price => 2.5,
|
12
|
+
:name => "MyText"
|
13
|
+
)
|
14
|
+
])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "renders a list of tests" do
|
18
|
+
render
|
19
|
+
assert_select "tr>td", :text => 2.5.to_s, :count => 2
|
20
|
+
assert_select "tr>td", :text => "MyText".to_s, :count => 2
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "tests/new", type: :view do
|
4
|
+
before(:each) do
|
5
|
+
assign(:test, Test.new(
|
6
|
+
:price => 1.5,
|
7
|
+
:name => "MyText"
|
8
|
+
))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "renders new test form" do
|
12
|
+
render
|
13
|
+
|
14
|
+
assert_select "form[action=?][method=?]", tests_path, "post" do
|
15
|
+
|
16
|
+
assert_select "input#test_price[name=?]", "test[price]"
|
17
|
+
|
18
|
+
assert_select "textarea#test_name[name=?]", "test[name]"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "tests/show", type: :view do
|
4
|
+
before(:each) do
|
5
|
+
@test = assign(:test, Test.create!(
|
6
|
+
:price => 2.5,
|
7
|
+
:name => "MyText"
|
8
|
+
))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "renders attributes in <p>" do
|
12
|
+
render
|
13
|
+
expect(rendered).to match(/2.5/)
|
14
|
+
expect(rendered).to match(/MyText/)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
|
+
|
3
|
+
# This model initially had no columns defined. If you add columns to the
|
4
|
+
# model remove the '{}' from the fixture names and add the columns immediately
|
5
|
+
# below each fixture, per the syntax in the comments below
|
6
|
+
#
|
7
|
+
one: {}
|
8
|
+
# column: value
|
9
|
+
#
|
10
|
+
two: {}
|
11
|
+
# column: value
|
@@ -0,0 +1,77 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
|
3
|
+
factory :product, class: Shopping::Product do
|
4
|
+
name {Faker::Food.ingredient}
|
5
|
+
price {10.00}
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
factory :cart_item, class: Shopping::CartItem do
|
10
|
+
product_id {Shopping::Product.first.id.to_s}
|
11
|
+
quantity 1
|
12
|
+
discount_code {Faker::App.name}
|
13
|
+
price {10.00}
|
14
|
+
name {Faker::Food.ingredient}
|
15
|
+
accept_order_at_percentage_of_price {0.2}
|
16
|
+
end
|
17
|
+
|
18
|
+
factory :client, class: Auth::Client do
|
19
|
+
redirect_urls ["http://www.google.com"]
|
20
|
+
user_id BSON::ObjectId.new
|
21
|
+
end
|
22
|
+
|
23
|
+
factory :user_mobile, class: User do
|
24
|
+
additional_login_param {Faker::Number.between(9822028511, 9922028511).to_s}
|
25
|
+
password 'password'
|
26
|
+
password_confirmation 'password'
|
27
|
+
end
|
28
|
+
|
29
|
+
factory :user_mobile_invalid, class: User do
|
30
|
+
additional_login_param {Faker::Name.name}
|
31
|
+
password 'password'
|
32
|
+
password_confirmation 'password'
|
33
|
+
end
|
34
|
+
|
35
|
+
factory :user_mobile_confirmed, class: User do
|
36
|
+
additional_login_param {Faker::Number.between(9822028511, 9922028511).to_s}
|
37
|
+
password 'password'
|
38
|
+
password_confirmation 'password'
|
39
|
+
additional_login_param_status 2
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
factory :user, class: User do
|
44
|
+
email { Faker::Internet.email }
|
45
|
+
password 'password'
|
46
|
+
password_confirmation 'password'
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
factory :user_confirmed, class: User do
|
51
|
+
email { Faker::Internet.email }
|
52
|
+
password 'password'
|
53
|
+
password_confirmation 'password'
|
54
|
+
confirmed_at Time.now
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
factory :user_update, class: User do
|
59
|
+
email {Faker::Internet.email}
|
60
|
+
current_password 'password'
|
61
|
+
end
|
62
|
+
|
63
|
+
factory :admin, class: User do
|
64
|
+
email { Faker::Internet.email }
|
65
|
+
password 'password'
|
66
|
+
password_confirmation 'password'
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
factory :admin_confirmed, class: Admin do
|
71
|
+
email { Faker::Internet.email }
|
72
|
+
password 'password'
|
73
|
+
password_confirmation 'password'
|
74
|
+
confirmed_at Time.now
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#additional_login_param_feature_spec.rb
|
2
|
+
require "rails_helper"
|
3
|
+
|
4
|
+
RSpec.feature "additional login param + its redirect", :otp_feature => true, :type => :feature, :js => true do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Auth.configuration.stub_otp_api_calls
|
8
|
+
ActionController::Base.allow_forgery_protection = true
|
9
|
+
User.delete_all
|
10
|
+
Auth::Client.delete_all
|
11
|
+
@u = User.new(attributes_for(:user_confirmed))
|
12
|
+
@u.save
|
13
|
+
@c = Auth::Client.new(:resource_id => @u.id, :api_key => "test")
|
14
|
+
@c.redirect_urls = ["http://www.google.com"]
|
15
|
+
@c.app_ids << "test_app_id"
|
16
|
+
@c.versioned_create
|
17
|
+
@u.client_authentication["test_app_id"] = "test_es"
|
18
|
+
@u.save
|
19
|
+
@ap_key = @c.api_key
|
20
|
+
end
|
21
|
+
|
22
|
+
scenario " -- signs up with otp system -- " do
|
23
|
+
|
24
|
+
ActionController::Base.allow_forgery_protection = false
|
25
|
+
Auth.configuration.recaptcha = false
|
26
|
+
##visit the sign in page
|
27
|
+
visit new_user_session_path()
|
28
|
+
|
29
|
+
##visit the sign up page.
|
30
|
+
click_link("Sign In")
|
31
|
+
wait_for_ajax
|
32
|
+
##modal should open.
|
33
|
+
##then
|
34
|
+
## SET RECAPTCHA TO FALSE SO THAT IT DOESNT INTERFERE WITH THE REQUEST RESPONSE.
|
35
|
+
|
36
|
+
find("#show_sign_up").click
|
37
|
+
#puts "----------------VISITED NEW USER REGISTRATION--------------"
|
38
|
+
fill_in('Email', :with => '9822028511')
|
39
|
+
fill_in('Password', :with => 'password')
|
40
|
+
fill_in('Password confirmation', :with => 'password')
|
41
|
+
wait_for_ajax
|
42
|
+
find("#submit").trigger("click")
|
43
|
+
wait_for_ajax
|
44
|
+
|
45
|
+
@last_user_created = User.order_by(:confirmation_sent_at => 'desc').first
|
46
|
+
old_session_id = $redis.hget(@last_user_created.id.to_s + "_two_factor_sms_otp","otp_session_id")
|
47
|
+
|
48
|
+
fill_in('user_otp', :with => old_session_id)
|
49
|
+
find('#otp_submit').click
|
50
|
+
wait_for_ajax
|
51
|
+
#expect(page).to have_text("Verifying your OTP")
|
52
|
+
wait_for_ajax
|
53
|
+
##search for the user account with additio
|
54
|
+
u = User.where(:additional_login_param => '9822028511', :additional_login_param_status => 2).first
|
55
|
+
|
56
|
+
expect(u).not_to be_nil
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,680 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.feature "", :type => :feature, :js => true do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
ActionController::Base.allow_forgery_protection = true
|
7
|
+
User.delete_all
|
8
|
+
Auth::Client.delete_all
|
9
|
+
@u = User.new(attributes_for(:user_confirmed))
|
10
|
+
@u.save
|
11
|
+
@c = Auth::Client.new(:resource_id => @u.id, :api_key => "test")
|
12
|
+
@c.redirect_urls = ["http://www.google.com"]
|
13
|
+
@c.app_ids << "test_app_id"
|
14
|
+
@c.versioned_create
|
15
|
+
@u.client_authentication["test_app_id"] = "test_es"
|
16
|
+
@u.save
|
17
|
+
@ap_key = @c.api_key
|
18
|
+
end
|
19
|
+
|
20
|
+
context " -- oauth tests -- " do
|
21
|
+
|
22
|
+
context " -- google oauth test -- ", google: true do
|
23
|
+
|
24
|
+
before(:all) do
|
25
|
+
@oauth_provider = :google_oauth2
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
scenario " -- it can sign in with oauth2 -- ", js: true do
|
30
|
+
|
31
|
+
Auth.configuration.recaptcha = false
|
32
|
+
##visit the sign in page
|
33
|
+
visit new_user_session_path
|
34
|
+
|
35
|
+
click_link("Sign In")
|
36
|
+
wait_for_ajax
|
37
|
+
|
38
|
+
mock_auth_hash(@oauth_provider)
|
39
|
+
|
40
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
41
|
+
|
42
|
+
l = find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']")
|
43
|
+
l.click
|
44
|
+
#find(:xpath, "//a[@href='/authenticate/omniauth/users/#{@oauth_provider.to_s}']").click
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
expect(page).to have_content("Sign Out")
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
scenario " -- creates new user first time with oauth, on subsequent sign in , will update access_token and expiration -- ", js: true do
|
54
|
+
|
55
|
+
Auth.configuration.recaptcha = false
|
56
|
+
##visit the sign in page
|
57
|
+
visit new_user_session_path
|
58
|
+
|
59
|
+
click_link("Sign In")
|
60
|
+
wait_for_ajax
|
61
|
+
|
62
|
+
mock_auth_hash(@oauth_provider)
|
63
|
+
|
64
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
65
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
66
|
+
|
67
|
+
|
68
|
+
click_link "Sign Out"
|
69
|
+
|
70
|
+
###
|
71
|
+
###
|
72
|
+
###
|
73
|
+
### TRY TO SIGN IN AGAIN USING SAME OAUTH.
|
74
|
+
|
75
|
+
Auth.configuration.recaptcha = false
|
76
|
+
##visit the sign in page
|
77
|
+
visit new_user_session_path
|
78
|
+
|
79
|
+
click_link("Sign In")
|
80
|
+
wait_for_ajax
|
81
|
+
|
82
|
+
mock_auth_hash(@oauth_provider,'new_token',50000)
|
83
|
+
|
84
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
85
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
86
|
+
|
87
|
+
expect(page).to have_content("Sign Out")
|
88
|
+
|
89
|
+
u = User.where(:email => "rrphotosoft@gmail.com").first
|
90
|
+
expect(u.identities[0]["access_token"]).to eql('new_token')
|
91
|
+
expect(u.identities[0]["token_expires_at"]).to eql(50000)
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
scenario "visit sign_in with redirect_url + valid_api_key => visit sign_up => create account pending confirmation => visit confirmation url => then sign in again => get redirected to the redirection url with es and authentication_token.", js: true do
|
97
|
+
Auth.configuration.recaptcha = false
|
98
|
+
##visit the sign in page
|
99
|
+
visit new_user_session_path({:redirect_url => "http://www.google.com", :api_key => @ap_key, :current_app_id => "test_app_id"})
|
100
|
+
|
101
|
+
|
102
|
+
##visit the sign up page.
|
103
|
+
click_link("Sign In")
|
104
|
+
|
105
|
+
wait_for_ajax
|
106
|
+
|
107
|
+
find("#show_sign_up").click
|
108
|
+
#puts "----------------VISITED NEW USER REGISTRATION--------------"
|
109
|
+
fill_in('Email', :with => 'retard@gmail.com')
|
110
|
+
fill_in('Password', :with => 'password')
|
111
|
+
fill_in('Password confirmation', :with => 'password')
|
112
|
+
wait_for_ajax
|
113
|
+
find("#submit").trigger("click")
|
114
|
+
wait_for_ajax
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
##now visit he confirmation url.
|
121
|
+
u = User.where(:email => 'retard@gmail.com').first
|
122
|
+
confirmation_token = u.confirmation_token
|
123
|
+
visit user_confirmation_path({:confirmation_token => confirmation_token})
|
124
|
+
|
125
|
+
u.reload
|
126
|
+
|
127
|
+
click_link("Sign In")
|
128
|
+
wait_for_ajax
|
129
|
+
|
130
|
+
#puts u.attributes.to_s
|
131
|
+
puts " ----------------- trying to sign in with new user ------------------------------"
|
132
|
+
fill_in('Email',:with => 'retard@gmail.com')
|
133
|
+
fill_in('Password', :with => 'password')
|
134
|
+
find("#submit").trigger("click")
|
135
|
+
sleep(5)
|
136
|
+
##should redirect to the redirect url.
|
137
|
+
expected_es = u.client_authentication["test_app_id"]
|
138
|
+
expect(current_url =~ /google/).to be_truthy
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
##with this scenario will see error in console< that is expected>
|
144
|
+
scenario "any error in omniauth -> goes to omniauth error page", js: true do
|
145
|
+
|
146
|
+
OmniAuth.config.test_mode = true
|
147
|
+
Auth.configuration.recaptcha = false
|
148
|
+
##visit the sign in page
|
149
|
+
visit new_user_session_path
|
150
|
+
|
151
|
+
click_link("Sign In")
|
152
|
+
wait_for_ajax
|
153
|
+
|
154
|
+
mock_auth_hash(@oauth_provider,nil,nil,"simulate_error")
|
155
|
+
|
156
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
157
|
+
|
158
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
159
|
+
|
160
|
+
expect(page).to have_content("error")
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
##THIS IS SIMULATED BY FIRST CREATING A NEW OAUTH USER.
|
167
|
+
##THEN WE SET ITS VERSION TO 0
|
168
|
+
##AFTER THAT WE GO AGAIN TO OAUTH AND TRY TO SIGN IN.
|
169
|
+
##SINCE VERSION IS 0, MONGOID VERSIONED ATOMIC UPDATE, WILL FAIL
|
170
|
+
##THIS WILL LEAD TO A FAILURE OF THE UPDATE OF ACCESS_TOKENA AND EXPIRES_AT.
|
171
|
+
scenario "failure to update access_token and expires_at goes to omniauth error page, with appropriate error message ", js: true do
|
172
|
+
|
173
|
+
Auth.configuration.recaptcha = false
|
174
|
+
##visit the sign in page
|
175
|
+
visit new_user_session_path
|
176
|
+
|
177
|
+
click_link("Sign In")
|
178
|
+
wait_for_ajax
|
179
|
+
|
180
|
+
mock_auth_hash(@oauth_provider)
|
181
|
+
|
182
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
183
|
+
|
184
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
185
|
+
|
186
|
+
click_link("Sign Out")
|
187
|
+
|
188
|
+
#u = User.where(:email => "rrphotosoft@gmail.com").first
|
189
|
+
#u.version = 0
|
190
|
+
#u.save
|
191
|
+
|
192
|
+
User.class_eval do
|
193
|
+
after_save :set_op_success_to_false
|
194
|
+
def set_op_success_to_false
|
195
|
+
self.op_success = false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
Auth.configuration.recaptcha = false
|
200
|
+
##visit the sign in page
|
201
|
+
visit new_user_session_path
|
202
|
+
|
203
|
+
click_link("Sign In")
|
204
|
+
wait_for_ajax
|
205
|
+
|
206
|
+
mock_auth_hash(@oauth_provider)
|
207
|
+
|
208
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
209
|
+
|
210
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
211
|
+
|
212
|
+
|
213
|
+
expect(page).to have_content("Failed to update the acceess token and token expires at")
|
214
|
+
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
##try to simulate by creating a after_create callback which will delete identities, this will make it feel like the create failed, and this will lead to a failure fo the create.
|
220
|
+
scenario "failure to create new oauth user, goes to omniauth error page, with error message ", js: true do
|
221
|
+
User.skip_callback(:save, :after, :set_op_success_to_false)
|
222
|
+
Auth.configuration.recaptcha = false
|
223
|
+
##visit the sign in page
|
224
|
+
visit new_user_session_path
|
225
|
+
|
226
|
+
click_link("Sign In")
|
227
|
+
wait_for_ajax
|
228
|
+
|
229
|
+
mock_auth_hash(@oauth_provider)
|
230
|
+
|
231
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
232
|
+
|
233
|
+
User.class_eval do
|
234
|
+
after_save :set_op_success_to_false
|
235
|
+
def set_op_success_to_false
|
236
|
+
|
237
|
+
self.op_success = false
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
242
|
+
|
243
|
+
expect(page).to have_content("Failed to create new identity")
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
##THIS CAN BE SIMULATED BY CALLING CONFIRM AFTER_SAVE
|
251
|
+
##SIGN IN WILL FAIL IF , WE UNSET THE PASSWORD, POST_SAVE
|
252
|
+
scenario "failure to sign in resource after creating or updating it, will lead to appropriate error", js: true do
|
253
|
+
User.skip_callback(:save, :after, :set_op_success_to_false)
|
254
|
+
|
255
|
+
Auth.configuration.recaptcha = false
|
256
|
+
##visit the sign in page
|
257
|
+
visit new_user_session_path
|
258
|
+
|
259
|
+
click_link("Sign In")
|
260
|
+
wait_for_ajax
|
261
|
+
|
262
|
+
mock_auth_hash(@oauth_provider)
|
263
|
+
|
264
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
265
|
+
|
266
|
+
User.class_eval do
|
267
|
+
before_save :remove_confirmed_at
|
268
|
+
def remove_confirmed_at
|
269
|
+
self.confirmed_at = nil
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
274
|
+
|
275
|
+
##THIS HAPPENS BECAUSE WE TRY TO SIGN IN AN UNCONFIRMED USER, AND SO IT WILL GIVE THAT AS THE ERROR, AND AT THE SAME TIME REDIRECT TO THE AFTER_SIGN_IN_PATH.
|
276
|
+
expect(page).to have_content("You have to confirm your email address before continuing.")
|
277
|
+
expect(page).to have_content("You need to Sign in to continue.")
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
scenario "failure to provide oauth resource, goes to omniauth error page, with no_resource error message", js: true do
|
282
|
+
User.skip_callback(:save, :after, :set_op_success_to_false)
|
283
|
+
User.skip_callback(:save, :before, :remove_confirmed_at)
|
284
|
+
|
285
|
+
Auth.configuration.recaptcha = false
|
286
|
+
##visit the sign in page
|
287
|
+
visit new_user_session_path
|
288
|
+
|
289
|
+
click_link("Sign In")
|
290
|
+
wait_for_ajax
|
291
|
+
Rails.application.env_config["omniauth.model"] = nil
|
292
|
+
mock_auth_hash(@oauth_provider)
|
293
|
+
|
294
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
295
|
+
|
296
|
+
##THIS HAPPENS BECAUSE WE TRY TO SIGN IN AN UNCONFIRMED USER, AND SO IT WILL GIVE THAT AS THE ERROR, AND AT THE SAME TIME REDIRECT TO THE AFTER_SIGN_IN_PATH.
|
297
|
+
expect(page).to have_content("No resource was specified in the omniauth callback request.")
|
298
|
+
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
|
305
|
+
context " -- facebook oauth test -- ", facebook: true do
|
306
|
+
|
307
|
+
before(:all) do
|
308
|
+
@oauth_provider = :facebook
|
309
|
+
end
|
310
|
+
|
311
|
+
scenario " -- it can sign in with oauth2 -- ", js: true do
|
312
|
+
|
313
|
+
Auth.configuration.recaptcha = false
|
314
|
+
##visit the sign in page
|
315
|
+
visit new_user_session_path
|
316
|
+
|
317
|
+
click_link("Sign In")
|
318
|
+
wait_for_ajax
|
319
|
+
|
320
|
+
mock_auth_hash(@oauth_provider)
|
321
|
+
|
322
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
323
|
+
find(:xpath, "//a[@href='/authenticate/omniauth/users/#{@oauth_provider.to_s}']").click
|
324
|
+
|
325
|
+
expect(page).to have_content("Sign Out")
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
scenario " -- creates new user first time with oauth, on subsequent sign in , will update access_token and expiration -- ", js: true do
|
331
|
+
|
332
|
+
Auth.configuration.recaptcha = false
|
333
|
+
##visit the sign in page
|
334
|
+
visit new_user_session_path
|
335
|
+
|
336
|
+
click_link("Sign In")
|
337
|
+
wait_for_ajax
|
338
|
+
|
339
|
+
mock_auth_hash(@oauth_provider)
|
340
|
+
|
341
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
342
|
+
find(:xpath, "//a[@href='/authenticate/omniauth/users/#{@oauth_provider.to_s}']").click
|
343
|
+
|
344
|
+
|
345
|
+
click_link "Sign Out"
|
346
|
+
|
347
|
+
###
|
348
|
+
###
|
349
|
+
###
|
350
|
+
### TRY TO SIGN IN AGAIN USING SAME OAUTH.
|
351
|
+
|
352
|
+
Auth.configuration.recaptcha = false
|
353
|
+
##visit the sign in page
|
354
|
+
visit new_user_session_path
|
355
|
+
|
356
|
+
click_link("Sign In")
|
357
|
+
wait_for_ajax
|
358
|
+
|
359
|
+
mock_auth_hash(@oauth_provider,'new_token',50000)
|
360
|
+
|
361
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
362
|
+
find(:xpath, "//a[@href='/authenticate/omniauth/users/#{@oauth_provider.to_s}']").click
|
363
|
+
|
364
|
+
expect(page).to have_content("Sign Out")
|
365
|
+
|
366
|
+
u = User.where(:email => "rrphotosoft@gmail.com").first
|
367
|
+
expect(u.identities[0]["access_token"]).to eql('new_token')
|
368
|
+
expect(u.identities[0]["token_expires_at"]).to eql(50000)
|
369
|
+
|
370
|
+
end
|
371
|
+
|
372
|
+
|
373
|
+
scenario "visit sign_in with redirect_url + valid_api_key => visit sign_up => create account pending confirmation => visit confirmation url => then sign in again => get redirected to the redirection url with es and authentication_token.", js: true do
|
374
|
+
Auth.configuration.recaptcha = false
|
375
|
+
##visit the sign in page
|
376
|
+
visit new_user_session_path({:redirect_url => "http://www.google.com", :api_key => @ap_key, :current_app_id => "test_app_id"})
|
377
|
+
|
378
|
+
puts "----------------FINISHED NEW USER SESSION PATH----------------"
|
379
|
+
##visit the sign up page.
|
380
|
+
click_link("Sign In")
|
381
|
+
wait_for_ajax
|
382
|
+
##modal should open.
|
383
|
+
##then
|
384
|
+
## SET RECAPTCHA TO FALSE SO THAT IT DOESNT INTERFERE WITH THE REQUEST RESPONSE.
|
385
|
+
|
386
|
+
find("#show_sign_up").click
|
387
|
+
#puts "----------------VISITED NEW USER REGISTRATION--------------"
|
388
|
+
fill_in('Email', :with => 'retard@gmail.com')
|
389
|
+
fill_in('Password', :with => 'password')
|
390
|
+
fill_in('Password confirmation', :with => 'password')
|
391
|
+
wait_for_ajax
|
392
|
+
find("#submit").trigger("click")
|
393
|
+
wait_for_ajax
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
##now visit he confirmation url.
|
400
|
+
u = User.where(:email => 'retard@gmail.com').first
|
401
|
+
confirmation_token = u.confirmation_token
|
402
|
+
visit user_confirmation_path({:confirmation_token => confirmation_token})
|
403
|
+
|
404
|
+
u.reload
|
405
|
+
|
406
|
+
click_link("Sign In")
|
407
|
+
wait_for_ajax
|
408
|
+
|
409
|
+
#puts u.attributes.to_s
|
410
|
+
puts " ----------------- trying to sign in with new user ------------------------------"
|
411
|
+
fill_in('Email',:with => 'retard@gmail.com')
|
412
|
+
fill_in('Password', :with => 'password')
|
413
|
+
find("#submit").trigger("click")
|
414
|
+
sleep(5)
|
415
|
+
##should redirect to the redirect url.
|
416
|
+
expected_es = u.client_authentication["test_app_id"]
|
417
|
+
if current_url=~/google/
|
418
|
+
expect("one").to eql("one")
|
419
|
+
end
|
420
|
+
|
421
|
+
end
|
422
|
+
|
423
|
+
scenario "any error in omniauth -> goes to omniauth error page", js: true do
|
424
|
+
|
425
|
+
OmniAuth.config.test_mode = true
|
426
|
+
Auth.configuration.recaptcha = false
|
427
|
+
##visit the sign in page
|
428
|
+
visit new_user_session_path
|
429
|
+
|
430
|
+
click_link("Sign In")
|
431
|
+
wait_for_ajax
|
432
|
+
|
433
|
+
mock_auth_hash(@oauth_provider,nil,nil,"simulate_error")
|
434
|
+
|
435
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
436
|
+
|
437
|
+
find(:xpath, "//a[@href='/authenticate/omniauth/users/#{@oauth_provider.to_s}']").click
|
438
|
+
|
439
|
+
expect(page).to have_content("error")
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
##THIS IS SIMULATED BY FIRST CREATING A NEW OAUTH USER.
|
446
|
+
##THEN WE SET ITS VERSION TO 0
|
447
|
+
##AFTER THAT WE GO AGAIN TO OAUTH AND TRY TO SIGN IN.
|
448
|
+
##SINCE VERSION IS 0, MONGOID VERSIONED ATOMIC UPDATE, WILL FAIL
|
449
|
+
##THIS WILL LEAD TO A FAILURE OF THE UPDATE OF ACCESS_TOKENA AND EXPIRES_AT.
|
450
|
+
scenario "failure to update access_token and expires_at goes to omniauth error page, with appropriate error message ", js: true do
|
451
|
+
|
452
|
+
Auth.configuration.recaptcha = false
|
453
|
+
##visit the sign in page
|
454
|
+
visit new_user_session_path
|
455
|
+
|
456
|
+
click_link("Sign In")
|
457
|
+
wait_for_ajax
|
458
|
+
|
459
|
+
mock_auth_hash(@oauth_provider)
|
460
|
+
|
461
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
462
|
+
|
463
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
464
|
+
|
465
|
+
click_link("Sign Out")
|
466
|
+
|
467
|
+
#u = User.where(:email => "rrphotosoft@gmail.com").first
|
468
|
+
#u.version = 0
|
469
|
+
#u.save
|
470
|
+
|
471
|
+
User.class_eval do
|
472
|
+
after_save :set_op_success_to_false
|
473
|
+
def set_op_success_to_false
|
474
|
+
self.op_success = false
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
Auth.configuration.recaptcha = false
|
479
|
+
##visit the sign in page
|
480
|
+
visit new_user_session_path
|
481
|
+
|
482
|
+
click_link("Sign In")
|
483
|
+
wait_for_ajax
|
484
|
+
|
485
|
+
mock_auth_hash(@oauth_provider)
|
486
|
+
|
487
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
488
|
+
|
489
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
490
|
+
|
491
|
+
|
492
|
+
expect(page).to have_content("Failed to update the acceess token and token expires at")
|
493
|
+
|
494
|
+
|
495
|
+
end
|
496
|
+
|
497
|
+
|
498
|
+
##try to simulate by creating a after_create callback which will delete identities, this will make it feel like the create failed, and this will lead to a failure fo the create.
|
499
|
+
scenario "failure to create new oauth user, goes to omniauth error page, with error message ", js: true do
|
500
|
+
User.skip_callback(:save, :after, :set_op_success_to_false)
|
501
|
+
Auth.configuration.recaptcha = false
|
502
|
+
##visit the sign in page
|
503
|
+
visit new_user_session_path
|
504
|
+
|
505
|
+
click_link("Sign In")
|
506
|
+
wait_for_ajax
|
507
|
+
|
508
|
+
mock_auth_hash(@oauth_provider)
|
509
|
+
|
510
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
511
|
+
|
512
|
+
User.class_eval do
|
513
|
+
after_save :set_op_success_to_false
|
514
|
+
def set_op_success_to_false
|
515
|
+
|
516
|
+
self.op_success = false
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
521
|
+
|
522
|
+
expect(page).to have_content("Failed to create new identity")
|
523
|
+
|
524
|
+
|
525
|
+
|
526
|
+
end
|
527
|
+
|
528
|
+
|
529
|
+
##THIS CAN BE SIMULATED BY CALLING CONFIRM AFTER_SAVE
|
530
|
+
##SIGN IN WILL FAIL IF , WE UNSET THE PASSWORD, POST_SAVE
|
531
|
+
scenario "failure to sign in resource after creating or updating it, will lead to appropriate error", js: true do
|
532
|
+
User.skip_callback(:save, :after, :set_op_success_to_false)
|
533
|
+
|
534
|
+
Auth.configuration.recaptcha = false
|
535
|
+
##visit the sign in page
|
536
|
+
visit new_user_session_path
|
537
|
+
|
538
|
+
click_link("Sign In")
|
539
|
+
wait_for_ajax
|
540
|
+
|
541
|
+
mock_auth_hash(@oauth_provider)
|
542
|
+
|
543
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
544
|
+
|
545
|
+
User.class_eval do
|
546
|
+
before_save :remove_confirmed_at
|
547
|
+
def remove_confirmed_at
|
548
|
+
self.confirmed_at = nil
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
553
|
+
|
554
|
+
##THIS HAPPENS BECAUSE WE TRY TO SIGN IN AN UNCONFIRMED USER, AND SO IT WILL GIVE THAT AS THE ERROR, AND AT THE SAME TIME REDIRECT TO THE AFTER_SIGN_IN_PATH.
|
555
|
+
expect(page).to have_content("You have to confirm your email address before continuing.")
|
556
|
+
expect(page).to have_content("You need to Sign in to continue.")
|
557
|
+
end
|
558
|
+
|
559
|
+
|
560
|
+
scenario "failure to provide oauth resource, goes to omniauth error page, with no_resource error message", js: true do
|
561
|
+
User.skip_callback(:save, :after, :set_op_success_to_false)
|
562
|
+
User.skip_callback(:save, :before, :remove_confirmed_at)
|
563
|
+
|
564
|
+
Auth.configuration.recaptcha = false
|
565
|
+
##visit the sign in page
|
566
|
+
visit new_user_session_path
|
567
|
+
|
568
|
+
click_link("Sign In")
|
569
|
+
wait_for_ajax
|
570
|
+
Rails.application.env_config["omniauth.model"] = nil
|
571
|
+
mock_auth_hash(@oauth_provider)
|
572
|
+
|
573
|
+
find("a[href='/authenticate/omniauth/users/#{@oauth_provider}']").click
|
574
|
+
|
575
|
+
##THIS HAPPENS BECAUSE WE TRY TO SIGN IN AN UNCONFIRMED USER, AND SO IT WILL GIVE THAT AS THE ERROR, AND AT THE SAME TIME REDIRECT TO THE AFTER_SIGN_IN_PATH.
|
576
|
+
expect(page).to have_content("No resource was specified in the omniauth callback request.")
|
577
|
+
|
578
|
+
|
579
|
+
end
|
580
|
+
|
581
|
+
end
|
582
|
+
|
583
|
+
end
|
584
|
+
|
585
|
+
context " -- topic web app request spec ", :topic_feature => true do
|
586
|
+
|
587
|
+
scenario "visit topic part after signing in, and everythign should work." , js: true do
|
588
|
+
ActionController::Base.allow_forgery_protection = false
|
589
|
+
Auth.configuration.recaptcha = false
|
590
|
+
##visit the sign in page
|
591
|
+
visit new_user_session_path({:api_key => @ap_key, :current_app_id => "test_app_id"})
|
592
|
+
|
593
|
+
puts "----------------FINISHED NEW USER SESSION PATH----------------"
|
594
|
+
##visit the sign up page.
|
595
|
+
click_link("Sign In")
|
596
|
+
wait_for_ajax
|
597
|
+
##modal should open.
|
598
|
+
##then
|
599
|
+
## SET RECAPTCHA TO FALSE SO THAT IT DOESNT INTERFERE WITH THE REQUEST RESPONSE.
|
600
|
+
|
601
|
+
find("#show_sign_up").click
|
602
|
+
#puts "----------------VISITED NEW USER REGISTRATION--------------"
|
603
|
+
fill_in('Email', :with => 'retard@gmail.com')
|
604
|
+
fill_in('Password', :with => 'password')
|
605
|
+
fill_in('Password confirmation', :with => 'password')
|
606
|
+
wait_for_ajax
|
607
|
+
find("#submit").trigger("click")
|
608
|
+
wait_for_ajax
|
609
|
+
##now visit he confirmation url.
|
610
|
+
u = User.where(:email => 'retard@gmail.com').first
|
611
|
+
confirmation_token = u.confirmation_token
|
612
|
+
visit user_confirmation_path({:confirmation_token => confirmation_token})
|
613
|
+
|
614
|
+
u.reload
|
615
|
+
|
616
|
+
click_link("Sign In")
|
617
|
+
wait_for_ajax
|
618
|
+
|
619
|
+
#puts u.attributes.to_s
|
620
|
+
puts " ----------------- trying to sign in with new user ------------------------------"
|
621
|
+
fill_in('Email',:with => 'retard@gmail.com')
|
622
|
+
fill_in('Password', :with => 'password')
|
623
|
+
find("#submit").trigger("click")
|
624
|
+
puts "sleeping"
|
625
|
+
sleep(5)
|
626
|
+
puts "visiting new topic path."
|
627
|
+
visit new_topic_path
|
628
|
+
expect(page).to have_text("Sign Out")
|
629
|
+
end
|
630
|
+
|
631
|
+
scenario "visit topic path without signing in, should redirect to sign in or sign up" , js: true , topic_feature: true do
|
632
|
+
visit new_topic_path
|
633
|
+
puts page.text
|
634
|
+
expect(page).to have_text("You need to Sign in to continue.")
|
635
|
+
|
636
|
+
end
|
637
|
+
|
638
|
+
|
639
|
+
end
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
=begin
|
650
|
+
|
651
|
+
|
652
|
+
|
653
|
+
scenario "user with omniauth authentication , tries to create an account with the same email" do
|
654
|
+
|
655
|
+
visit new_user_registration_path
|
656
|
+
page.should have_content("Sign in with GoogleOauth2")
|
657
|
+
mock_auth_hash
|
658
|
+
Rails.application.env_config["omniauth.model"] = "omniauth/users/"
|
659
|
+
#Rails.application.env_config["omniauth.auth"] =
|
660
|
+
click_link "Sign in with GoogleOauth2"
|
661
|
+
expect(page).to have_content("Logout")
|
662
|
+
ActionController::Base.allow_forgery_protection = false
|
663
|
+
click_link "Logout"
|
664
|
+
ActionController::Base.allow_forgery_protection = true
|
665
|
+
|
666
|
+
##oauth user has now been created.
|
667
|
+
|
668
|
+
visit new_user_registration_path
|
669
|
+
fill_in('Email', :with => 'rrphotosoft@gmail.com')
|
670
|
+
fill_in('Password', :with => 'password')
|
671
|
+
fill_in('Password confirmation', :with => 'password')
|
672
|
+
find('input[name="commit"]').click
|
673
|
+
expect(page).to have_content("Email is already taken")
|
674
|
+
|
675
|
+
end
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
=end
|
680
|
+
end
|