openstax_accounts 7.13.0 → 8.1.1
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.
- checksums.yaml +4 -4
- data/app/controllers/openstax/accounts/application_controller.rb +1 -1
- data/app/controllers/openstax/accounts/dev/accounts_controller.rb +1 -1
- data/app/controllers/openstax/accounts/dev/base_controller.rb +1 -1
- data/app/controllers/openstax/accounts/sessions_controller.rb +7 -8
- data/app/handlers/openstax/accounts/sessions_callback.rb +17 -37
- data/app/models/openstax/accounts/account.rb +33 -1
- data/app/models/openstax/accounts/group.rb +12 -8
- data/app/models/openstax/accounts/group_nesting.rb +8 -7
- data/app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb +1 -7
- data/app/routines/openstax/accounts/find_or_create_account.rb +9 -9
- data/app/routines/openstax/accounts/find_or_create_from_sso.rb +23 -0
- data/app/routines/openstax/accounts/sync_accounts.rb +1 -6
- data/config/routes.rb +11 -11
- data/db/migrate/0_create_openstax_accounts_accounts.rb +1 -1
- data/db/migrate/10_assign_missing_uuids_for_local_accounts.rb +2 -2
- data/db/migrate/11_add_support_identifier_to_accounts_accounts.rb +1 -1
- data/db/migrate/12_add_is_test_to_accounts_accounts.rb +1 -1
- data/db/migrate/13_add_school_type_to_accounts_accounts.rb +1 -1
- data/db/migrate/1_create_openstax_accounts_groups.rb +1 -1
- data/db/migrate/2_create_openstax_accounts_group_members.rb +1 -1
- data/db/migrate/3_create_openstax_accounts_group_owners.rb +1 -1
- data/db/migrate/4_create_openstax_accounts_group_nestings.rb +1 -1
- data/db/migrate/5_add_faculty_status_to_accounts_accounts.rb +1 -1
- data/db/migrate/6_add_salesforce_contact_id_to_accounts_accounts.rb +1 -1
- data/db/migrate/7_change_accounts_openstax_uid_to_be_nullable.rb +1 -1
- data/db/migrate/8_change_accounts_username_to_be_nullable.rb +1 -1
- data/db/migrate/9_add_uuid_and_role_to_accounts_accounts.rb +1 -1
- data/lib/omniauth/strategies/openstax.rb +6 -23
- data/lib/openstax/accounts/configuration.rb +16 -0
- data/lib/openstax/accounts/current_user_manager.rb +20 -0
- data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +5 -5
- data/lib/openstax/accounts/sso.rb +61 -0
- data/lib/openstax/accounts/version.rb +1 -1
- data/lib/openstax_accounts.rb +6 -7
- data/lib/tasks/sync.rake +3 -3
- data/spec/factories/openstax_accounts_account.rb +1 -1
- data/spec/factories/openstax_accounts_group.rb +3 -3
- data/spec/factories/openstax_accounts_group_member.rb +1 -1
- data/spec/factories/openstax_accounts_group_nesting.rb +1 -1
- data/spec/factories/openstax_accounts_group_owner.rb +1 -1
- metadata +34 -212
- data/Rakefile +0 -22
- data/spec/cassettes/OpenStax_Accounts_FindOrCreateAccount/can_create_users.yml +0 -303
- data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +0 -27
- data/spec/controllers/openstax/accounts/forwards_params_spec.rb +0 -75
- data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +0 -71
- data/spec/controllers/openstax/accounts/uses_this_engine_controller_spec.rb +0 -22
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/access_policies/account_access_policy.rb +0 -11
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/api/application_groups_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/application_users_controller.rb +0 -15
- data/spec/dummy/app/controllers/api/dummy_controller.rb +0 -12
- data/spec/dummy/app/controllers/api/group_members_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/group_nestings_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/group_owners_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/groups_controller.rb +0 -15
- data/spec/dummy/app/controllers/api/users_controller.rb +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/controllers/oauth_controller.rb +0 -10
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/anonymous_user.rb +0 -48
- data/spec/dummy/app/models/ownership.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -29
- data/spec/dummy/config.ru +0 -5
- data/spec/dummy/config/application.rb +0 -23
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -15
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -40
- data/spec/dummy/config/environments/production.rb +0 -82
- data/spec/dummy/config/environments/test.rb +0 -39
- data/spec/dummy/config/initializers/access_policies.rb +0 -1
- data/spec/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -75
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/openstax_accounts.rb +0 -14
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -45
- data/spec/dummy/config/secrets.yml +0 -8
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/1000_create_users.rb +0 -11
- data/spec/dummy/db/migrate/1001_create_ownerships.rb +0 -11
- data/spec/dummy/db/schema.rb +0 -113
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -5137
- data/spec/dummy/log/test.log +0 -162651
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/handlers/openstax/accounts/accounts_search_spec.rb +0 -63
- data/spec/handlers/openstax/accounts/dev/accounts_search_spec.rb +0 -55
- data/spec/handlers/openstax/accounts/sessions_callback_spec.rb +0 -119
- data/spec/lib/openstax/accounts/api_spec.rb +0 -212
- data/spec/lib/openstax/accounts/configuration_spec.rb +0 -39
- data/spec/lib/openstax/accounts/current_user_manager_spec.rb +0 -157
- data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +0 -57
- data/spec/models/openstax/accounts/account_spec.rb +0 -114
- data/spec/models/openstax/accounts/anonymous_account_spec.rb +0 -9
- data/spec/models/openstax/accounts/group_spec.rb +0 -51
- data/spec/routines/openstax/accounts/create_group_spec.rb +0 -32
- data/spec/routines/openstax/accounts/find_or_create_account_spec.rb +0 -76
- data/spec/routines/openstax/accounts/search_accounts_shared_examples.rb +0 -160
- data/spec/routines/openstax/accounts/search_accounts_spec.rb +0 -6
- data/spec/routines/openstax/accounts/search_local_accounts_spec.rb +0 -6
- data/spec/routines/openstax/accounts/sync_accounts_spec.rb +0 -101
- data/spec/routines/openstax/accounts/sync_groups_spec.rb +0 -143
- data/spec/spec_helper.rb +0 -109
- data/spec/vcr_helper.rb +0 -14
@@ -1,39 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
RSpec.describe Configuration do
|
4
|
-
|
5
|
-
let!(:config) { Configuration.new.tap {|c| c.openstax_accounts_url = "https://accounts.openstax.org"} }
|
6
|
-
let!(:a_fake_request) { OpenStruct.new(url: "http://foo.com") }
|
7
|
-
|
8
|
-
it "returns the default logout redirect when no explicit URL is set" do
|
9
|
-
expect(config.logout_redirect_url(a_fake_request)).to eq "https://accounts.openstax.org/logout"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "returns an explicitly-set string logout redirect URL when set" do
|
13
|
-
config.logout_redirect_url = "blah"
|
14
|
-
expect(config.logout_redirect_url(a_fake_request)).to eq "blah"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns the default URL when Proc logout redirect URL set and returns nil" do
|
18
|
-
config.logout_redirect_url = ->(request) { nil }
|
19
|
-
expect(config.logout_redirect_url(a_fake_request)).to eq "https://accounts.openstax.org/logout"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns the Proc URL when Proc logout redirect URL set and returns non-nil" do
|
23
|
-
config.logout_redirect_url = ->(request) { "howdy" }
|
24
|
-
expect(config.logout_redirect_url(a_fake_request)).to eq "howdy"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "says return_to urls not approved when nil" do
|
28
|
-
config.return_to_url_approver = ->(url) { true }
|
29
|
-
expect(config.is_return_to_url_approved?(nil)).to be_falsy
|
30
|
-
end
|
31
|
-
|
32
|
-
it "says return_to urls not approved when approver nil" do
|
33
|
-
config.return_to_url_approver = nil
|
34
|
-
expect(config.is_return_to_url_approved?("http://www.google.com")).to be_falsy
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
RSpec.describe CurrentUserManager do
|
4
|
-
let!(:account) { FactoryBot.create(:openstax_accounts_account,
|
5
|
-
username: 'some_user',
|
6
|
-
openstax_uid: 1) }
|
7
|
-
let!(:user) { User.create(:account => account) }
|
8
|
-
|
9
|
-
let!(:request) { double('request',
|
10
|
-
:host => 'localhost',
|
11
|
-
:ssl? => false) }
|
12
|
-
|
13
|
-
let!(:ssl_request) { double('request',
|
14
|
-
:host => 'localhost',
|
15
|
-
:ssl? => true) }
|
16
|
-
|
17
|
-
let!(:session) { {} }
|
18
|
-
|
19
|
-
let!(:cookies) { ActionDispatch::Cookies::CookieJar.new(
|
20
|
-
ActiveSupport::KeyGenerator.new(SecureRandom.hex),
|
21
|
-
'localhost', false,
|
22
|
-
encrypted_cookie_salt: 'encrypted cookie salt',
|
23
|
-
encrypted_signed_cookie_salt: 'encrypted signed cookie salt') }
|
24
|
-
|
25
|
-
let!(:current_user_manager) { CurrentUserManager.new(
|
26
|
-
request, session, cookies) }
|
27
|
-
|
28
|
-
context 'signing in' do
|
29
|
-
|
30
|
-
it 'signs in an account' do
|
31
|
-
expect(current_user_manager.signed_in?).to eq(false)
|
32
|
-
expect(current_user_manager.current_account).to(
|
33
|
-
eq(AnonymousAccount.instance))
|
34
|
-
expect(current_user_manager.current_user).to(
|
35
|
-
eq(AnonymousUser.instance))
|
36
|
-
|
37
|
-
current_user_manager.sign_in!(account)
|
38
|
-
|
39
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
40
|
-
expect(current_user_manager.current_account).to eq(account)
|
41
|
-
expect(current_user_manager.current_user).to eq(user)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'signs in a user' do
|
45
|
-
expect(current_user_manager.signed_in?).to eq(false)
|
46
|
-
expect(current_user_manager.current_account).to(
|
47
|
-
eq(AnonymousAccount.instance))
|
48
|
-
expect(current_user_manager.current_user).to(
|
49
|
-
eq(AnonymousUser.instance))
|
50
|
-
|
51
|
-
current_user_manager.sign_in!(user)
|
52
|
-
|
53
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
54
|
-
expect(current_user_manager.current_account).to eq(account)
|
55
|
-
expect(current_user_manager.current_user).to eq(user)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'from session' do
|
61
|
-
|
62
|
-
before(:each) do
|
63
|
-
current_user_manager.sign_in!(account)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'keeps a legitimate user signed in' do
|
67
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
68
|
-
expect(current_user_manager.current_account).to eq(account)
|
69
|
-
expect(current_user_manager.current_user).to eq(user)
|
70
|
-
|
71
|
-
# Secure cookies are not sent with non-SSL requests
|
72
|
-
unsecure_cookies = ActionDispatch::Cookies::CookieJar.new(
|
73
|
-
ActiveSupport::KeyGenerator.new(SecureRandom.hex),
|
74
|
-
'localhost', false,
|
75
|
-
encrypted_cookie_salt: 'encrypted cookie salt',
|
76
|
-
encrypted_signed_cookie_salt: 'encrypted signed cookie salt')
|
77
|
-
unsecure_cookies[:account_id] = cookies[:account_id]
|
78
|
-
|
79
|
-
current_user_manager = CurrentUserManager.new(
|
80
|
-
request, session, unsecure_cookies)
|
81
|
-
|
82
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
83
|
-
expect(current_user_manager.current_account).to eq(account)
|
84
|
-
expect(current_user_manager.current_user).to eq(user)
|
85
|
-
|
86
|
-
# But they are sent with SSL requests
|
87
|
-
current_user_manager = CurrentUserManager.new(
|
88
|
-
ssl_request, session, cookies)
|
89
|
-
|
90
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
91
|
-
expect(current_user_manager.current_account).to eq(account)
|
92
|
-
expect(current_user_manager.current_user).to eq(user)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'signs out an attacker attempting to hijack the session' do
|
96
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
97
|
-
expect(current_user_manager.current_account).to eq(account)
|
98
|
-
expect(current_user_manager.current_user).to eq(user)
|
99
|
-
|
100
|
-
# The protection relies on the attacker not being
|
101
|
-
# able to get the secure cookies
|
102
|
-
cookies.delete(:secure_account_id)
|
103
|
-
|
104
|
-
# The attacker can still access non-SSL pages
|
105
|
-
current_user_manager = CurrentUserManager.new(
|
106
|
-
request, session, cookies)
|
107
|
-
|
108
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
109
|
-
expect(current_user_manager.current_account).to eq(account)
|
110
|
-
expect(current_user_manager.current_user).to eq(user)
|
111
|
-
|
112
|
-
# But not SSL pages
|
113
|
-
current_user_manager = CurrentUserManager.new(
|
114
|
-
ssl_request, session, cookies)
|
115
|
-
|
116
|
-
expect(current_user_manager.signed_in?).to eq(false)
|
117
|
-
expect(current_user_manager.current_account).to(
|
118
|
-
eq(AnonymousAccount.instance))
|
119
|
-
expect(current_user_manager.current_user).to(
|
120
|
-
eq(AnonymousUser.instance))
|
121
|
-
|
122
|
-
# And after they logout, that's it
|
123
|
-
current_user_manager = CurrentUserManager.new(
|
124
|
-
request, session, cookies)
|
125
|
-
|
126
|
-
expect(current_user_manager.signed_in?).to eq(false)
|
127
|
-
expect(current_user_manager.current_account).to(
|
128
|
-
eq(AnonymousAccount.instance))
|
129
|
-
expect(current_user_manager.current_user).to(
|
130
|
-
eq(AnonymousUser.instance))
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'signing out' do
|
136
|
-
|
137
|
-
before(:each) { current_user_manager.sign_in!(account) }
|
138
|
-
|
139
|
-
it 'signs out users' do
|
140
|
-
expect(current_user_manager.signed_in?).to eq(true)
|
141
|
-
expect(current_user_manager.current_account).to eq(account)
|
142
|
-
expect(current_user_manager.current_user).to eq(user)
|
143
|
-
|
144
|
-
current_user_manager.sign_out!
|
145
|
-
|
146
|
-
expect(current_user_manager.signed_in?).to eq(false)
|
147
|
-
expect(current_user_manager.current_account).to(
|
148
|
-
eq(AnonymousAccount.instance))
|
149
|
-
expect(current_user_manager.current_user).to(
|
150
|
-
eq(AnonymousUser.instance))
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module OpenStax
|
2
|
-
module Accounts
|
3
|
-
module HasManyThroughGroups
|
4
|
-
module ActiveRecord
|
5
|
-
RSpec.describe Base do
|
6
|
-
let!(:account_1) { FactoryBot.create(:openstax_accounts_account,
|
7
|
-
username: 'some_user',
|
8
|
-
openstax_uid: 1) }
|
9
|
-
let!(:user_1) { User.create(:account => account_1) }
|
10
|
-
|
11
|
-
let!(:account_2) { FactoryBot.create(:openstax_accounts_account,
|
12
|
-
username: 'another_user',
|
13
|
-
openstax_uid: 2) }
|
14
|
-
let!(:user_2) { User.create(:account => account_2) }
|
15
|
-
|
16
|
-
let!(:group_nesting) { FactoryBot.create(:openstax_accounts_group_nesting) }
|
17
|
-
|
18
|
-
before(:each) do
|
19
|
-
group_nesting.member_group.add_member(account_1)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'allows users to retrieve all nested has_many_through_groups objects' do
|
23
|
-
expect(user_1.ownerships).to be_empty
|
24
|
-
|
25
|
-
o = Ownership.new
|
26
|
-
o.owner = user_2
|
27
|
-
o.save!
|
28
|
-
|
29
|
-
expect(user_1.reload.ownerships).to be_empty
|
30
|
-
|
31
|
-
o2 = Ownership.new
|
32
|
-
o2.owner = user_1
|
33
|
-
o2.save!
|
34
|
-
|
35
|
-
expect(user_1.reload.ownerships).to include(o2)
|
36
|
-
|
37
|
-
o3 = Ownership.new
|
38
|
-
o3.owner = group_nesting.member_group
|
39
|
-
o3.save!
|
40
|
-
|
41
|
-
expect(user_1.reload.ownerships).to include(o2)
|
42
|
-
expect(user_1.ownerships).to include(o3)
|
43
|
-
|
44
|
-
o4 = Ownership.new
|
45
|
-
o4.owner = group_nesting.container_group
|
46
|
-
o4.save!
|
47
|
-
|
48
|
-
expect(user_1.reload.ownerships).to include(o2)
|
49
|
-
expect(user_1.ownerships).to include(o3)
|
50
|
-
expect(user_1.ownerships).to include(o4)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax::Accounts
|
4
|
-
RSpec.describe Account, type: :model do
|
5
|
-
subject(:account) { FactoryBot.create(:openstax_accounts_account) }
|
6
|
-
|
7
|
-
it { is_expected.to validate_presence_of(:uuid) }
|
8
|
-
it { is_expected.to validate_uniqueness_of(:uuid).case_insensitive }
|
9
|
-
it { is_expected.to validate_uniqueness_of(:support_identifier).case_insensitive.allow_nil }
|
10
|
-
|
11
|
-
context 'validation' do
|
12
|
-
it 'requires a unique openstax_uid, if given' do
|
13
|
-
account.openstax_uid = nil
|
14
|
-
expect(account).to be_valid
|
15
|
-
|
16
|
-
account.openstax_uid = -1
|
17
|
-
account.save!
|
18
|
-
|
19
|
-
account_2 = FactoryBot.build(:openstax_accounts_account, openstax_uid: -1)
|
20
|
-
expect(account_2).not_to be_valid
|
21
|
-
expect(account_2.errors[:openstax_uid]).to eq(['has already been taken'])
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'allows nil username' do
|
25
|
-
account.username = nil
|
26
|
-
expect(account).to be_valid
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'requires unique username if not nil' do
|
30
|
-
expect{
|
31
|
-
FactoryBot.create(:openstax_accounts_account, username: account.username)
|
32
|
-
}.to raise_error(ActiveRecord::RecordInvalid)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'allows multiple accounts saved with nil username' do
|
36
|
-
FactoryBot.create(:openstax_accounts_account, username: nil)
|
37
|
-
expect{
|
38
|
-
FactoryBot.create(:openstax_accounts_account, username: nil)
|
39
|
-
}.not_to raise_error
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'requires a role' do
|
43
|
-
expect{
|
44
|
-
FactoryBot.create(:openstax_accounts_account, role: nil)
|
45
|
-
}.to raise_error(ActiveRecord::RecordInvalid)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'updates' do
|
50
|
-
before do
|
51
|
-
account.syncing = false
|
52
|
-
account.openstax_uid = 1
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'stubbing' do
|
56
|
-
it 'does not send updates to accounts' do
|
57
|
-
expect(OpenStax::Accounts::Api).not_to receive(:update_account)
|
58
|
-
|
59
|
-
account.username = 'Stubbed User'
|
60
|
-
account.save!
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'not stubbing' do
|
65
|
-
before(:all) { OpenStax::Accounts.configuration.enable_stubbing = false }
|
66
|
-
after(:all) { OpenStax::Accounts.configuration.enable_stubbing = true }
|
67
|
-
|
68
|
-
context 'syncing' do
|
69
|
-
before{ account.syncing = true }
|
70
|
-
|
71
|
-
it 'does not send updates to accounts' do
|
72
|
-
expect(OpenStax::Accounts::Api).not_to receive(:update_account)
|
73
|
-
|
74
|
-
account.username = 'Syncing User'
|
75
|
-
account.save!
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'not syncing' do
|
80
|
-
context 'invalid openstax_uid' do
|
81
|
-
it 'does not send updates to accounts' do
|
82
|
-
expect(OpenStax::Accounts::Api).not_to receive(:update_account)
|
83
|
-
|
84
|
-
account.openstax_uid = nil
|
85
|
-
account.username = 'Nil User'
|
86
|
-
account.save!
|
87
|
-
|
88
|
-
account.openstax_uid = 0
|
89
|
-
account.username = 'Zeroth User'
|
90
|
-
account.save!
|
91
|
-
|
92
|
-
account.openstax_uid = -1
|
93
|
-
account.username = 'Negative User'
|
94
|
-
account.save!
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'valid openstax_uid' do
|
99
|
-
it 'sends updates to accounts' do
|
100
|
-
expect(OpenStax::Accounts::Api).to receive(:update_account).once
|
101
|
-
|
102
|
-
account.username = 'Real User'
|
103
|
-
account.save!
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'is not anonymous' do
|
111
|
-
expect(Account.new.is_anonymous?).to eq false
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax::Accounts
|
4
|
-
RSpec.describe Group, type: :model do
|
5
|
-
context 'validation' do
|
6
|
-
it 'requires a unique openstax_uid' do
|
7
|
-
group = FactoryBot.build(:openstax_accounts_group, openstax_uid: nil)
|
8
|
-
expect(group).not_to be_valid
|
9
|
-
expect(group.errors[:openstax_uid]).to eq(['can\'t be blank'])
|
10
|
-
|
11
|
-
group.openstax_uid = 1
|
12
|
-
group.save!
|
13
|
-
|
14
|
-
group_2 = FactoryBot.build(:openstax_accounts_group, openstax_uid: 1)
|
15
|
-
expect(group_2).not_to be_valid
|
16
|
-
expect(group_2.errors[:openstax_uid]).to eq(['has already been taken'])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'no stubbing' do
|
21
|
-
before(:all) do
|
22
|
-
@stubbing = OpenStax::Accounts.configuration.enable_stubbing?
|
23
|
-
OpenStax::Accounts.configuration.enable_stubbing = false
|
24
|
-
end
|
25
|
-
|
26
|
-
after(:all) { OpenStax::Accounts.configuration.enable_stubbing = @stubbing }
|
27
|
-
|
28
|
-
let!(:requestor) { FactoryBot.create(:openstax_accounts_account) }
|
29
|
-
let!(:group) do
|
30
|
-
FactoryBot.build(:openstax_accounts_group).tap{ |group| group.requestor = requestor }
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'calls OpenStax Accounts when created' do
|
34
|
-
expect(OpenStax::Accounts::Api).to receive(:create_group).with(requestor, group)
|
35
|
-
group.save!
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'fails to save if the requestor is nil' do
|
39
|
-
group.requestor = nil
|
40
|
-
expect(OpenStax::Accounts::Api).not_to receive(:create_group)
|
41
|
-
expect(group.save).to eq false
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'does not call OpenStax Accounts if the requestor is temp' do
|
45
|
-
group.requestor.access_token = nil
|
46
|
-
expect(OpenStax::Accounts::Api).not_to receive(:create_group)
|
47
|
-
group.save!
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Accounts
|
5
|
-
|
6
|
-
RSpec.describe CreateGroup, type: :routine do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
@previous_enable_stubbing = OpenStax::Accounts.configuration.enable_stubbing
|
10
|
-
OpenStax::Accounts.configuration.enable_stubbing = true
|
11
|
-
end
|
12
|
-
|
13
|
-
let!(:owner) { FactoryBot.create :openstax_accounts_account }
|
14
|
-
|
15
|
-
it 'can create groups' do
|
16
|
-
group = CreateGroup[owner: owner, name: 'Test', is_public: true]
|
17
|
-
expect(group).to be_persisted
|
18
|
-
|
19
|
-
expect(group.name).to eq 'Test'
|
20
|
-
expect(group.is_public).to eq true
|
21
|
-
expect(group.owners.first).to eq owner
|
22
|
-
expect(group.members).to be_empty
|
23
|
-
end
|
24
|
-
|
25
|
-
after(:all) do
|
26
|
-
OpenStax::Accounts.configuration.enable_stubbing = @previous_enable_stubbing
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|