osso 0.0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.buildkite/hooks/environment +9 -0
  3. data/.buildkite/hooks/pre-command +7 -0
  4. data/.buildkite/pipeline.yml +6 -0
  5. data/.buildkite/template.yml +5 -0
  6. data/.gitignore +10 -0
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +81 -0
  9. data/CODE_OF_CONDUCT.md +130 -0
  10. data/Gemfile +18 -0
  11. data/Gemfile.lock +176 -0
  12. data/LICENSE +111 -0
  13. data/README.md +2 -0
  14. data/Rakefile +14 -0
  15. data/bin/console +8 -0
  16. data/bin/setup +8 -0
  17. data/config/database.yml +14 -0
  18. data/db/schema.rb +133 -0
  19. data/lib/osso.rb +11 -0
  20. data/lib/osso/Rakefile +13 -0
  21. data/lib/osso/db/migrate/20190909230109_enable_uuid.rb +7 -0
  22. data/lib/osso/db/migrate/20200328135750_create_users.rb +12 -0
  23. data/lib/osso/db/migrate/20200328143303_create_oauth_tables.rb +57 -0
  24. data/lib/osso/db/migrate/20200328143305_create_identity_providers.rb +12 -0
  25. data/lib/osso/db/migrate/20200411184535_add_provider_id_to_users.rb +7 -0
  26. data/lib/osso/db/migrate/20200411192645_create_enterprise_accounts.rb +15 -0
  27. data/lib/osso/db/migrate/20200413132407_add_oauth_clients.rb +13 -0
  28. data/lib/osso/db/migrate/20200413142511_create_authorization_codes.rb +15 -0
  29. data/lib/osso/db/migrate/20200413163451_create_access_tokens.rb +13 -0
  30. data/lib/osso/db/migrate/20200502120616_create_redirect_uris_and_drop_from_oauth_clients.rb +13 -0
  31. data/lib/osso/db/migrate/20200502135008_add_oauth_client_id_to_enterprise_accounts_and_identity_providers.rb +6 -0
  32. data/lib/osso/db/migrate/20200714223226_add_identity_provider_service_enum.rb +17 -0
  33. data/lib/osso/db/migrate/20200715154211_rename_idp_fields_on_identity_provider_to_sso.rb +6 -0
  34. data/lib/osso/db/migrate/20200715205801_add_name_to_enterprise_account.rb +5 -0
  35. data/lib/osso/graphql/mutation.rb +16 -0
  36. data/lib/osso/graphql/mutations.rb +12 -0
  37. data/lib/osso/graphql/mutations/base_mutation.rb +41 -0
  38. data/lib/osso/graphql/mutations/configure_identity_provider.rb +36 -0
  39. data/lib/osso/graphql/mutations/create_enterprise_account.rb +25 -0
  40. data/lib/osso/graphql/mutations/create_identity_provider.rb +30 -0
  41. data/lib/osso/graphql/mutations/set_identity_provider.rb +27 -0
  42. data/lib/osso/graphql/query.rb +25 -0
  43. data/lib/osso/graphql/resolvers.rb +12 -0
  44. data/lib/osso/graphql/resolvers/enterprise_account.rb +25 -0
  45. data/lib/osso/graphql/resolvers/enterprise_accounts.rb +17 -0
  46. data/lib/osso/graphql/resolvers/oauth_clients.rb +15 -0
  47. data/lib/osso/graphql/schema.rb +46 -0
  48. data/lib/osso/graphql/types.rb +15 -0
  49. data/lib/osso/graphql/types/base_enum.rb +10 -0
  50. data/lib/osso/graphql/types/base_input_object.rb +10 -0
  51. data/lib/osso/graphql/types/base_object.rb +12 -0
  52. data/lib/osso/graphql/types/enterprise_account.rb +33 -0
  53. data/lib/osso/graphql/types/identity_provider.rb +37 -0
  54. data/lib/osso/graphql/types/identity_provider_service.rb +12 -0
  55. data/lib/osso/graphql/types/oauth_client.rb +20 -0
  56. data/lib/osso/graphql/types/user.rb +17 -0
  57. data/lib/osso/helpers/auth.rb +71 -0
  58. data/lib/osso/helpers/helpers.rb +8 -0
  59. data/lib/osso/lib/app_config.rb +20 -0
  60. data/lib/osso/lib/oauth2_token.rb +38 -0
  61. data/lib/osso/lib/route_map.rb +28 -0
  62. data/lib/osso/models/access_token.rb +29 -0
  63. data/lib/osso/models/authorization_code.rb +14 -0
  64. data/lib/osso/models/enterprise_account.rb +28 -0
  65. data/lib/osso/models/identity_provider.rb +48 -0
  66. data/lib/osso/models/models.rb +16 -0
  67. data/lib/osso/models/oauth_client.rb +32 -0
  68. data/lib/osso/models/redirect_uri.rb +20 -0
  69. data/lib/osso/models/saml_provider.rb +49 -0
  70. data/lib/osso/models/saml_providers/azure_saml_provider.rb +22 -0
  71. data/lib/osso/models/saml_providers/okta_saml_provider.rb +23 -0
  72. data/lib/osso/models/user.rb +24 -0
  73. data/lib/osso/rake.rb +4 -0
  74. data/lib/osso/routes/admin.rb +41 -0
  75. data/lib/osso/routes/auth.rb +67 -0
  76. data/lib/osso/routes/oauth.rb +63 -0
  77. data/lib/osso/routes/routes.rb +10 -0
  78. data/lib/osso/routes/views/error.erb +1 -0
  79. data/lib/osso/routes/views/multiple_providers.erb +1 -0
  80. data/lib/osso/version.rb +5 -0
  81. data/lib/tasks/bootstrap.rake +16 -0
  82. data/osso-rb.gemspec +40 -0
  83. data/spec/factories/authorization_code.rb +10 -0
  84. data/spec/factories/enterprise_account.rb +46 -0
  85. data/spec/factories/identity_providers.rb +49 -0
  86. data/spec/factories/oauth_client.rb +12 -0
  87. data/spec/factories/redirect_uri.rb +14 -0
  88. data/spec/factories/user.rb +18 -0
  89. data/spec/graphql/mutations/configure_identity_provider_spec.rb +75 -0
  90. data/spec/graphql/mutations/create_enterprise_account_spec.rb +68 -0
  91. data/spec/graphql/mutations/create_identity_provider_spec.rb +104 -0
  92. data/spec/graphql/query/enterprise_account_spec.rb +68 -0
  93. data/spec/graphql/query/enterprise_accounts_spec.rb +44 -0
  94. data/spec/graphql/query/identity_provider_spec.rb +65 -0
  95. data/spec/graphql/query/oauth_clients_account_spec.rb +48 -0
  96. data/spec/models/azure_saml_provider_spec.rb +19 -0
  97. data/spec/models/identity_provider_spec.rb +17 -0
  98. data/spec/models/okta_saml_provider_spec.rb +20 -0
  99. data/spec/routes/admin_spec.rb +60 -0
  100. data/spec/routes/app_spec.rb +6 -0
  101. data/spec/routes/auth_spec.rb +112 -0
  102. data/spec/routes/oauth_spec.rb +134 -0
  103. data/spec/spec_helper.rb +68 -0
  104. data/spec/support/spec_app.rb +9 -0
  105. data/spec/support/views/admin.erb +5 -0
  106. metadata +348 -0
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :authorization_code, class: Osso::Models::AuthorizationCode do
5
+ id { SecureRandom.uuid }
6
+ redirect_uri { Faker::Internet.url(path: '/saml-box/callback') }
7
+ user
8
+ oauth_client
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :enterprise_account, class: Osso::Models::EnterpriseAccount do
5
+ id { SecureRandom.uuid }
6
+ name { Faker::Company.name }
7
+ domain { Faker::Internet.domain_name }
8
+ oauth_client
9
+ end
10
+
11
+ factory :enterprise_with_okta, parent: :enterprise_account do
12
+ after :create do |enterprise|
13
+ create(
14
+ :okta_identity_provider,
15
+ domain: enterprise.domain,
16
+ enterprise_account_id: enterprise.id,
17
+ )
18
+ end
19
+ end
20
+
21
+ factory :enterprise_with_azure, parent: :enterprise_account do
22
+ after :create do |enterprise|
23
+ create(
24
+ :azure_identity_provider,
25
+ domain: enterprise.domain,
26
+ enterprise_account_id: enterprise.id,
27
+ )
28
+ end
29
+ end
30
+
31
+ factory :enterprise_with_multiple_providers, parent: :enterprise_account do
32
+ after :create do |enterprise|
33
+ create(
34
+ :okta_identity_provider,
35
+ domain: enterprise.domain,
36
+ enterprise_account_id: enterprise.id,
37
+ )
38
+
39
+ create(
40
+ :azure_identity_provider,
41
+ domain: enterprise.domain,
42
+ enterprise_account_id: enterprise.id,
43
+ )
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :identity_provider, class: Osso::Models::IdentityProvider do
5
+ id { SecureRandom.uuid }
6
+ domain { Faker::Internet.domain_name }
7
+ oauth_client
8
+
9
+ factory :okta_identity_provider, parent: :identity_provider do
10
+ service { 'OKTA' }
11
+ sso_url do
12
+ 'https://dev-162024.okta.com/app/vcardmedev162024_rubydemo2_1/exk51326b3U1941Hf4x6/sso/saml'
13
+ end
14
+ end
15
+
16
+ factory :azure_identity_provider, parent: :identity_provider do
17
+ service { 'AZURE' }
18
+ sso_url do
19
+ 'https://login.microsoftonline.com/0af6c610-c40c-4683-9ea4-f25e509b8172/saml2'
20
+ end
21
+ end
22
+
23
+ factory :configured_identity_provider, parent: :identity_provider do
24
+ sso_cert do
25
+ <<~CERT
26
+ -----BEGIN CERTIFICATE-----
27
+ MIIDpDCCAoygAwIBAgIGAXEiD4LlMA0GCSqGSIb3DQEBCwUAMIGSMQswCQYDVQQGEwJVUzETMBEG
28
+ A1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwET2t0YTEU
29
+ MBIGA1UECwwLU1NPUHJvdmlkZXIxEzARBgNVBAMMCmRldi0xNjIwMjQxHDAaBgkqhkiG9w0BCQEW
30
+ DWluZm9Ab2t0YS5jb20wHhcNMjAwMzI4MTY1MTU0WhcNMzAwMzI4MTY1MjU0WjCBkjELMAkGA1UE
31
+ BhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNV
32
+ BAoMBE9rdGExFDASBgNVBAsMC1NTT1Byb3ZpZGVyMRMwEQYDVQQDDApkZXYtMTYyMDI0MRwwGgYJ
33
+ KoZIhvcNAQkBFg1pbmZvQG9rdGEuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
34
+ wsnP4UTfv3bxR5Jh0at51Dqjj+fKxFznzFW3XA5NbF2SlRLjeYcvj3+47TC0eP6xOsLWfnvdnx4v
35
+ dd9Ufn7jDCo5pL3JykMVEh2I0szF3RLC+a532ArcwgU9Px48+rWVwPkASS7l4NHAM4+gOBHJMQt2
36
+ AMohPT0kU41P8BEPzfwhNyiEXR66JNZIJUE8fM3Vpgnxm/VSwYzJf0NfOyfxv8JczF0zkDbpE7Tk
37
+ 3Ww/PFFLoMxWzanWGJQ+blnhv6UV6H4fcfAbcwAplOdIVHjS2ghYBvYNGahuFxjia0+6csyZGrt8
38
+ H4XmR5Dr+jXY5K1b1VOA0k19/FCnHHN/smn25wIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBgD9NE
39
+ 4OCuR1+vucV8S1T6XXIL2hB7bXBAZEVHZ1aErRzktgXAMgVwG267vIkD5VOXBiTy9yNU5LK6G3k2
40
+ zewU190sL1dMfyPnoVZyn94nvwe9A+on0tmZdmk00xirKk3FJdacnZNE9Dl/afIrcNf6xAm0WsU9
41
+ kbMiRwwvjO4TAiygDQzbrRC8ZfmT3hpBa3aTUzAccrvEQcgarLk4r7UjXP7a2mCN3UIIh+snN2Ms
42
+ vXHL0r6fM3xbniz+5lleWtPFw73yySBc8znkWZ4Tn8Lh0r6o5nCRYbr2REUB7ZIfiIyBbZxIp4kv
43
+ a+habbnQDFiNVzEd8OPXHh4EqLxOPDRW
44
+ -----END CERTIFICATE-----
45
+ CERT
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :oauth_client, class: Osso::Models::OauthClient do
5
+ id { SecureRandom.uuid }
6
+ name { Faker::Internet.domain_name }
7
+ after(:create) do |client|
8
+ create(:primary_redirect_uri, oauth_client: client)
9
+ create(:redirect_uri, oauth_client: client)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :redirect_uri, class: Osso::Models::RedirectUri do
5
+ id { SecureRandom.uuid }
6
+ uri { Faker::Internet.url }
7
+ primary { false }
8
+ oauth_client
9
+ end
10
+
11
+ factory :primary_redirect_uri, parent: :redirect_uri do
12
+ primary { true }
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :user, class: Osso::Models::User do
5
+ id { SecureRandom.uuid }
6
+ email { Faker::Internet.email }
7
+ idp_id { SecureRandom.hex(32) }
8
+ identity_provider { create(:okta_identity_provider) }
9
+ enterprise_account
10
+ after(:create) do |user|
11
+ create(
12
+ :authorization_code,
13
+ user: user,
14
+ redirect_uri: user.oauth_client.redirect_uri_values.sample,
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Osso::GraphQL::Schema do
6
+ describe 'ConfigureIdentityProvider' do
7
+ let(:enterprise_account) { create(:enterprise_account) }
8
+ let(:identity_provider) { create(:identity_provider, enterprise_account: enterprise_account) }
9
+ let(:variables) do
10
+ {
11
+ input: {
12
+ id: identity_provider.id,
13
+ service: 'OKTA',
14
+ ssoUrl: 'https://example.com',
15
+ ssoCert: 'BEGIN_CERTIFICATE',
16
+ },
17
+ }
18
+ end
19
+ let(:mutation) do
20
+ <<~GRAPHQL
21
+ mutation ConfigureIdentityProvider($input: ConfigureIdentityProviderInput!) {
22
+ configureIdentityProvider(input: $input) {
23
+ identityProvider {
24
+ id
25
+ domain
26
+ configured
27
+ enterpriseAccountId
28
+ service
29
+ acsUrl
30
+ ssoCert
31
+ ssoUrl
32
+ }
33
+ }
34
+ }
35
+ GRAPHQL
36
+ end
37
+
38
+ subject do
39
+ described_class.execute(
40
+ mutation,
41
+ variables: variables,
42
+ context: { scope: current_scope },
43
+ )
44
+ end
45
+
46
+ describe 'for an admin user' do
47
+ let(:current_scope) { :admin }
48
+ it 'configures an identity provider' do
49
+ expect(subject.dig('data', 'configureIdentityProvider', 'identityProvider', 'configured')).
50
+ to be true
51
+ end
52
+ end
53
+
54
+ describe 'for an email scoped user' do
55
+ let(:domain) { Faker::Internet.domain_name }
56
+ let(:current_scope) { domain }
57
+ let(:enterprise_account) { create(:enterprise_account, domain: domain) }
58
+ let(:identity_provider) { create(:identity_provider, enterprise_account: enterprise_account, domain: domain) }
59
+
60
+ it 'configures an identity provider' do
61
+ expect(subject.dig('data', 'configureIdentityProvider', 'identityProvider', 'domain')).
62
+ to eq(domain)
63
+ end
64
+ end
65
+
66
+ describe 'for the wrong email scoped user' do
67
+ let(:domain) { Faker::Internet.domain_name }
68
+ let(:current_scope) { domain }
69
+
70
+ it 'does not configure an identity provider' do
71
+ expect(subject.dig('errors')).to_not be_empty
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Osso::GraphQL::Schema do
6
+ describe 'CreateIdentityProvider' do
7
+ let(:domain) { Faker::Internet.domain_name }
8
+ let(:variables) do
9
+ {
10
+ input: {
11
+ name: Faker::Company.name,
12
+ domain: domain,
13
+ },
14
+ }
15
+ end
16
+
17
+ let(:mutation) do
18
+ <<~GRAPHQL
19
+ mutation CreateEnterpriseAccount($input: CreateEnterpriseAccountInput!) {
20
+ createEnterpriseAccount(input: $input) {
21
+ enterpriseAccount {
22
+ id
23
+ domain
24
+ name
25
+ status
26
+ }
27
+ }
28
+ }
29
+ GRAPHQL
30
+ end
31
+
32
+ subject do
33
+ described_class.execute(
34
+ mutation,
35
+ variables: variables,
36
+ context: { scope: current_scope },
37
+ )
38
+ end
39
+
40
+ describe 'for an admin user' do
41
+ let(:current_scope) { :admin }
42
+ it 'creates an Enterprise Account' do
43
+ expect { subject }.to change { Osso::Models::EnterpriseAccount.count }.by(1)
44
+ expect(subject.dig('data', 'createEnterpriseAccount', 'enterpriseAccount', 'domain')).
45
+ to eq(domain)
46
+ end
47
+ end
48
+
49
+ describe 'for an email scoped user' do
50
+ let(:current_scope) { domain }
51
+
52
+ it 'creates an Enterprise Account' do
53
+ expect { subject }.to change { Osso::Models::EnterpriseAccount.count }.by(1)
54
+ expect(subject.dig('data', 'createEnterpriseAccount', 'enterpriseAccount', 'domain')).
55
+ to eq(domain)
56
+ end
57
+ end
58
+ describe 'for the wrong email scoped user' do
59
+ let(:current_scope) { 'foo.com' }
60
+
61
+ it 'does not create an Enterprise Account' do
62
+ expect { subject }.to_not(change { Osso::Models::EnterpriseAccount.count })
63
+ expect(subject.dig('data', 'createEnterpriseAccount', 'enterpriseAccount', 'domain')).
64
+ to be_nil
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Osso::GraphQL::Schema do
6
+ describe 'CreateIdentityProvider' do
7
+ let(:enterprise_account) { create(:enterprise_account) }
8
+ let(:mutation) do
9
+ <<~GRAPHQL
10
+ mutation CreateIdentityProvider($input: CreateIdentityProviderInput!) {
11
+ createIdentityProvider(input: $input) {
12
+ identityProvider {
13
+ id
14
+ domain
15
+ enterpriseAccountId
16
+ service
17
+ acsUrl
18
+ }
19
+ }
20
+ }
21
+ GRAPHQL
22
+ end
23
+
24
+ subject do
25
+ described_class.execute(
26
+ mutation,
27
+ variables: variables,
28
+ context: { scope: current_scope },
29
+ )
30
+ end
31
+
32
+ describe 'for an admin user' do
33
+ let(:current_scope) { :admin }
34
+ describe 'without a service' do
35
+ let(:variables) { { input: { enterpriseAccountId: enterprise_account.id } } }
36
+
37
+ it 'creates an identity provider' do
38
+ expect { subject }.to change { enterprise_account.identity_providers.count }.by(1)
39
+ expect(subject.dig('data', 'createIdentityProvider', 'identityProvider', 'domain')).
40
+ to eq(enterprise_account.domain)
41
+ end
42
+ end
43
+
44
+ describe 'with a service' do
45
+ let(:variables) { { input: { enterpriseAccountId: enterprise_account.id, service: 'OKTA' } } }
46
+
47
+ it 'creates an identity provider for given service ' do
48
+ expect { subject }.to change { enterprise_account.identity_providers.count }.by(1)
49
+ expect(subject.dig('data', 'createIdentityProvider', 'identityProvider', 'service')).
50
+ to eq('OKTA')
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'for an email scoped user' do
56
+ let(:domain) { Faker::Internet.domain_name }
57
+ let(:current_scope) { domain }
58
+ let(:enterprise_account) { create(:enterprise_account, domain: domain) }
59
+
60
+ describe 'without a service' do
61
+ let(:variables) { { input: { enterpriseAccountId: enterprise_account.id } } }
62
+
63
+ it 'creates an identity provider' do
64
+ expect { subject }.to change { enterprise_account.identity_providers.count }.by(1)
65
+ expect(subject.dig('data', 'createIdentityProvider', 'identityProvider', 'domain')).
66
+ to eq(domain)
67
+ end
68
+ end
69
+
70
+ describe 'with a service' do
71
+ let(:variables) { { input: { enterpriseAccountId: enterprise_account.id, service: 'OKTA' } } }
72
+
73
+ it 'creates an identity provider for given service ' do
74
+ expect { subject }.to change { enterprise_account.identity_providers.count }.by(1)
75
+ expect(subject.dig('data', 'createIdentityProvider', 'identityProvider', 'service')).
76
+ to eq('OKTA')
77
+ end
78
+ end
79
+ end
80
+
81
+ describe 'for a wrong email scoped user' do
82
+ let(:domain) { Faker::Internet.domain_name }
83
+ let(:current_scope) { domain }
84
+ let(:enterprise_account) { create(:enterprise_account, domain: domain) }
85
+ let(:target_account) { create(:enterprise_account) }
86
+
87
+ describe 'without a service' do
88
+ let(:variables) { { input: { enterpriseAccountId: target_account.id } } }
89
+
90
+ it 'does not creates a identity provider' do
91
+ expect { subject }.to_not(change { Osso::Models::IdentityProvider.count })
92
+ end
93
+ end
94
+
95
+ describe 'with a service' do
96
+ let(:variables) { { input: { enterpriseAccountId: target_account.id, service: 'OKTA' } } }
97
+
98
+ it 'does not creates a identity provider' do
99
+ expect { subject }.to_not(change { Osso::Models::IdentityProvider.count })
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Osso::GraphQL::Schema do
6
+ describe 'EnterpriseAccount' do
7
+ let(:domain) { Faker::Internet.domain_name }
8
+ let(:variables) { { domain: domain } }
9
+ let(:query) do
10
+ <<~GRAPHQL
11
+ query EnterpriseAccount($domain: String!) {
12
+ enterpriseAccount(domain: $domain) {
13
+ domain
14
+ id
15
+ identityProviders {
16
+ id
17
+ service
18
+ domain
19
+ acsUrl
20
+ ssoCert
21
+ ssoUrl
22
+ configured
23
+ }
24
+ name
25
+ status
26
+ }
27
+ }
28
+ GRAPHQL
29
+ end
30
+
31
+ before do
32
+ create(:enterprise_account)
33
+ create(:enterprise_account, domain: domain)
34
+ end
35
+
36
+ subject do
37
+ described_class.execute(
38
+ query,
39
+ variables: variables,
40
+ context: { scope: current_scope },
41
+ )
42
+ end
43
+
44
+ describe 'for an admin user' do
45
+ let(:current_scope) { :admin }
46
+ it 'returns Enterprise Account for domain' do
47
+ expect(subject['errors']).to be_nil
48
+ expect(subject.dig('data', 'enterpriseAccount', 'domain')).to eq(domain)
49
+ end
50
+ end
51
+
52
+ describe 'for an email scoped user' do
53
+ let(:current_scope) { domain }
54
+ it 'returns Enterprise Account for domain' do
55
+ expect(subject['errors']).to be_nil
56
+ expect(subject.dig('data', 'enterpriseAccount', 'domain')).to eq(domain)
57
+ end
58
+ end
59
+
60
+ describe 'for the wrong email scoped user' do
61
+ let(:current_scope) { 'bar.com' }
62
+ it 'returns Enterprise Account for domain' do
63
+ expect(subject['errors']).to be_nil
64
+ expect(subject.dig('data', 'enterpriseAccount')).to be_nil
65
+ end
66
+ end
67
+ end
68
+ end