osso 0.0.8 → 0.1.2

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.buildkite/pipeline.yml +1 -0
  3. data/.rubocop.yml +4 -16
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +60 -55
  6. data/Rakefile +1 -0
  7. data/bin/console +3 -0
  8. data/db/schema.rb +4 -4
  9. data/lib/osso.rb +1 -0
  10. data/lib/osso/db/migrate/20210201220556_add_generic_saml_to_provider_service_enum.rb +28 -0
  11. data/lib/osso/graphql/mutations/configure_identity_provider.rb +4 -1
  12. data/lib/osso/graphql/mutations/create_enterprise_account.rb +4 -1
  13. data/lib/osso/graphql/mutations/create_identity_provider.rb +8 -3
  14. data/lib/osso/graphql/mutations/create_oauth_client.rb +4 -1
  15. data/lib/osso/graphql/mutations/delete_enterprise_account.rb +4 -1
  16. data/lib/osso/graphql/mutations/delete_identity_provider.rb +4 -1
  17. data/lib/osso/graphql/mutations/delete_oauth_client.rb +4 -1
  18. data/lib/osso/graphql/mutations/invite_admin_user.rb +6 -0
  19. data/lib/osso/graphql/mutations/regenerate_oauth_credentials.rb +10 -1
  20. data/lib/osso/graphql/mutations/set_redirect_uris.rb +2 -0
  21. data/lib/osso/graphql/mutations/update_app_config.rb +4 -1
  22. data/lib/osso/graphql/query.rb +26 -31
  23. data/lib/osso/graphql/schema.rb +0 -1
  24. data/lib/osso/graphql/types/identity_provider_service.rb +1 -0
  25. data/lib/osso/lib/analytics.rb +55 -0
  26. data/lib/osso/lib/route_map.rb +2 -0
  27. data/lib/osso/models/account.rb +1 -1
  28. data/lib/osso/models/identity_provider.rb +3 -3
  29. data/lib/osso/routes/admin.rb +47 -5
  30. data/lib/osso/routes/auth.rb +2 -0
  31. data/lib/osso/routes/oauth.rb +1 -1
  32. data/lib/osso/version.rb +1 -1
  33. data/lib/tasks/bootstrap.rake +6 -4
  34. data/osso-rb.gemspec +5 -3
  35. data/spec/graphql/mutations/create_identity_provider_spec.rb +1 -1
  36. data/spec/models/identity_provider_spec.rb +1 -1
  37. data/spec/routes/admin_spec.rb +54 -9
  38. data/spec/routes/auth_spec.rb +5 -3
  39. data/spec/routes/oauth_spec.rb +7 -13
  40. data/spec/spec_helper.rb +2 -0
  41. data/spec/support/views/saml_login_form.erb +1 -0
  42. metadata +39 -15
  43. data/spec/routes/app_spec.rb +0 -6
@@ -91,7 +91,7 @@ describe Osso::GraphQL::Schema do
91
91
  },
92
92
  }
93
93
  end
94
-
94
+
95
95
  it 'creates an identity provider' do
96
96
  expect { subject }.to change { enterprise_account.identity_providers.count }.by(1)
97
97
  expect(subject.dig('data', 'createIdentityProvider', 'identityProvider', 'domain')).
@@ -66,7 +66,7 @@ describe Osso::Models::IdentityProvider do
66
66
  idp_cert: subject.sso_cert,
67
67
  idp_sso_target_url: subject.sso_url,
68
68
  issuer: subject.sso_issuer,
69
- name_identifier_format: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
69
+ name_identifier_format: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
70
70
  )
71
71
  end
72
72
  end
@@ -4,23 +4,68 @@ require 'spec_helper'
4
4
 
5
5
  describe Osso::Admin do
6
6
  describe 'get /admin' do
7
- it 'redirects to /login without a session' do
7
+ it 'renders the admin layout' do
8
8
  get('/admin')
9
9
 
10
- expect(last_response).to be_redirect
11
- follow_redirect!
12
- expect(last_request.url).to match('/login')
10
+ expect(last_response).to be_ok
13
11
  end
12
+ end
14
13
 
15
- xit 'renders the admin page for a valid session token' do
16
- password = SecureRandom.urlsafe_base64(16)
17
- account = create(:verified_account, password: password)
14
+ describe 'post /graphql' do
15
+ let(:account) { create(:account) }
18
16
 
19
- post('/login', { email: account.email, password: password })
17
+ it 'runs a GraphQL query with a valid jwt' do
18
+ allow_any_instance_of(described_class.rodauth).to receive(:logged_in?).and_return(true)
19
+ allow(Osso::Models::Account).to receive(:find).and_return(account)
20
+ allow(Osso::GraphQL::Schema).to receive(:execute).and_return({ graphql: true })
20
21
 
21
- get('/admin')
22
+ header 'Content-Type', 'application/json'
23
+ post('/graphql')
24
+
25
+ expect(last_response).to be_ok
26
+ expect(last_json_response).to eq({ graphql: true })
27
+ end
28
+
29
+ it 'returns a 400 for an invalid jwt' do
30
+ header 'Content-Type', 'application/json'
31
+ header 'Authorization', 'Bearer bad-token'
32
+ post('/graphql')
33
+
34
+ expect(last_response.status).to eq 400
35
+ end
36
+
37
+ it 'returns a 401 without a jwt' do
38
+ header 'Content-Type', 'application/json'
39
+ post('/graphql')
40
+
41
+ expect(last_response.status).to eq 401
42
+ end
43
+ end
44
+
45
+ describe 'post /idp' do
46
+ let(:domain) { Faker::Internet.domain_name }
47
+
48
+ before do
49
+ create(:configured_identity_provider, domain: domain)
50
+ end
51
+
52
+ it 'returns true when an available IDP is found' do
53
+ header 'Content-Type', 'application/json'
54
+ header 'Accept', 'application/json'
55
+ post('/idp', { domain: domain }.to_json)
56
+
57
+ expect(last_response).to be_ok
58
+ expect(last_json_response).to eq({ onboarded: true })
59
+ end
60
+
61
+ it 'returns false when an available IDP is not found' do
62
+ header 'Content-Type', 'application/json'
63
+ header 'Accept', 'application/json'
64
+
65
+ post('/idp', { domain: domain.reverse}.to_json)
22
66
 
23
67
  expect(last_response).to be_ok
68
+ expect(last_json_response).to eq({ onboarded: false })
24
69
  end
25
70
  end
26
71
  end
@@ -6,12 +6,13 @@ describe Osso::Auth do
6
6
  before do
7
7
  described_class.set(:views, spec_views)
8
8
  end
9
- describe 'get /auth/saml/:uuid' do
9
+
10
+ describe 'post /auth/saml/:uuid' do
10
11
  describe 'for an Okta SAML provider' do
11
12
  let(:enterprise) { create(:enterprise_with_okta) }
12
13
  let(:okta_provider) { enterprise.identity_providers.first }
13
14
  it 'uses omniauth saml' do
14
- get("/auth/saml/#{okta_provider.id}")
15
+ post("/auth/saml/#{okta_provider.id}")
15
16
 
16
17
  expect(last_response).to be_redirect
17
18
  follow_redirect!
@@ -23,7 +24,7 @@ describe Osso::Auth do
23
24
  let(:enterprise) { create(:enterprise_with_okta) }
24
25
  let(:azure_provider) { enterprise.identity_providers.first }
25
26
  it 'uses omniauth saml' do
26
- get("/auth/saml/#{azure_provider.id}")
27
+ post("/auth/saml/#{azure_provider.id}")
27
28
 
28
29
  expect(last_response).to be_redirect
29
30
  follow_redirect!
@@ -31,6 +32,7 @@ describe Osso::Auth do
31
32
  end
32
33
  end
33
34
  end
35
+
34
36
  describe 'post /auth/saml/:uuid/callback' do
35
37
  describe 'for an Okta SAML provider' do
36
38
  let(:enterprise) { create(:enterprise_with_okta) }
@@ -28,7 +28,7 @@ describe Osso::Oauth do
28
28
  end
29
29
 
30
30
  describe 'for a request without email or domain' do
31
- it 'redirects to /auth/saml/:provider_id' do
31
+ it 'renders the hosted login page' do
32
32
  get(
33
33
  '/oauth/authorize',
34
34
  client_id: client.identifier,
@@ -42,7 +42,7 @@ describe Osso::Oauth do
42
42
  end
43
43
 
44
44
  describe 'for an enterprise domain with one SAML provider' do
45
- it 'redirects to /auth/saml/:provider_id' do
45
+ it 'renders the saml login form' do
46
46
  enterprise = create(:enterprise_with_okta, oauth_client: client)
47
47
 
48
48
  get(
@@ -55,9 +55,7 @@ describe Osso::Oauth do
55
55
 
56
56
  provider_id = enterprise.identity_providers.first.id
57
57
 
58
- expect(last_response).to be_redirect
59
- follow_redirect!
60
- expect(last_request.url).to match("auth/saml/#{provider_id}")
58
+ expect(last_response.body).to match(provider_id)
61
59
  end
62
60
  end
63
61
 
@@ -79,7 +77,7 @@ describe Osso::Oauth do
79
77
  end
80
78
 
81
79
  describe "for an existing user's email address" do
82
- it 'redirects to /auth/saml/:provider_id' do
80
+ it 'renders the saml login form' do
83
81
  enterprise = create(:enterprise_with_okta, oauth_client: client)
84
82
  provider_id = enterprise.identity_providers.first.id
85
83
  user = create(:user, email: "user@#{enterprise.domain}", identity_provider_id: provider_id)
@@ -92,14 +90,12 @@ describe Osso::Oauth do
92
90
  redirect_uri: client.redirect_uri_values.sample,
93
91
  )
94
92
 
95
- expect(last_response).to be_redirect
96
- follow_redirect!
97
- expect(last_request.url).to match("auth/saml/#{provider_id}")
93
+ expect(last_response.body).to match(provider_id)
98
94
  end
99
95
  end
100
96
 
101
97
  describe "for a new user's email address belonging to an enterprise with one SAML provider" do
102
- it 'redirects to /auth/saml/:provider_id' do
98
+ it 'renders the saml login form' do
103
99
  enterprise = create(:enterprise_with_okta, oauth_client: client)
104
100
 
105
101
  get(
@@ -112,9 +108,7 @@ describe Osso::Oauth do
112
108
 
113
109
  provider_id = enterprise.identity_providers.first.id
114
110
 
115
- expect(last_response).to be_redirect
116
- follow_redirect!
117
- expect(last_request.url).to match("auth/saml/#{provider_id}")
111
+ expect(last_response.body).to match(provider_id)
118
112
  end
119
113
  end
120
114
 
data/spec/spec_helper.rb CHANGED
@@ -80,5 +80,7 @@ RSpec.configure do |config|
80
80
 
81
81
  OmniAuth.config.test_mode = true
82
82
  OmniAuth.config.logger = Logger.new('/dev/null')
83
+ OmniAuth.config.request_validation_phase = proc {}
84
+
83
85
  WebMock.disable_net_connect!(allow_localhost: true)
84
86
  end
@@ -0,0 +1 @@
1
+ <%= @providers.first.id %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Bauch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-11 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: posthog-ruby
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rack
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rack-protection
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 2.1.0
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.1.0
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: rake
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -170,32 +198,26 @@ dependencies:
170
198
  requirements:
171
199
  - - "~>"
172
200
  - !ruby/object:Gem::Version
173
- version: 2.6.0
201
+ version: '2.9'
174
202
  type: :runtime
175
203
  prerelease: false
176
204
  version_requirements: !ruby/object:Gem::Requirement
177
205
  requirements:
178
206
  - - "~>"
179
207
  - !ruby/object:Gem::Version
180
- version: 2.6.0
208
+ version: '2.9'
181
209
  - !ruby/object:Gem::Dependency
182
210
  name: sequel
183
211
  requirement: !ruby/object:Gem::Requirement
184
212
  requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '5.37'
188
- - - "<"
213
+ - - "~>"
189
214
  - !ruby/object:Gem::Version
190
215
  version: '5.40'
191
216
  type: :runtime
192
217
  prerelease: false
193
218
  version_requirements: !ruby/object:Gem::Requirement
194
219
  requirements:
195
- - - ">="
196
- - !ruby/object:Gem::Version
197
- version: '5.37'
198
- - - "<"
220
+ - - "~>"
199
221
  - !ruby/object:Gem::Version
200
222
  version: '5.40'
201
223
  - !ruby/object:Gem::Dependency
@@ -238,14 +260,14 @@ dependencies:
238
260
  requirements:
239
261
  - - ">="
240
262
  - !ruby/object:Gem::Version
241
- version: '0'
263
+ version: 2.0.22
242
264
  type: :runtime
243
265
  prerelease: false
244
266
  version_requirements: !ruby/object:Gem::Requirement
245
267
  requirements:
246
268
  - - ">="
247
269
  - !ruby/object:Gem::Version
248
- version: '0'
270
+ version: 2.0.22
249
271
  - !ruby/object:Gem::Dependency
250
272
  name: sinatra-contrib
251
273
  requirement: !ruby/object:Gem::Requirement
@@ -365,6 +387,7 @@ files:
365
387
  - lib/osso/db/migrate/20201110190754_remove_oauth_client_id_from_enterprise_accounts.rb
366
388
  - lib/osso/db/migrate/20201112160120_add_ping_to_identity_provider_service_enum.rb
367
389
  - lib/osso/db/migrate/20201125143501_add_salesforce_to_provider_service_enum.rb
390
+ - lib/osso/db/migrate/20210201220556_add_generic_saml_to_provider_service_enum.rb
368
391
  - lib/osso/error/account_configuration_error.rb
369
392
  - lib/osso/error/error.rb
370
393
  - lib/osso/error/missing_saml_attribute_error.rb
@@ -407,6 +430,7 @@ files:
407
430
  - lib/osso/graphql/types/oauth_client.rb
408
431
  - lib/osso/graphql/types/redirect_uri.rb
409
432
  - lib/osso/graphql/types/redirect_uri_input.rb
433
+ - lib/osso/lib/analytics.rb
410
434
  - lib/osso/lib/app_config.rb
411
435
  - lib/osso/lib/oauth2_token.rb
412
436
  - lib/osso/lib/route_map.rb
@@ -455,7 +479,6 @@ files:
455
479
  - spec/models/enterprise_account_spec.rb
456
480
  - spec/models/identity_provider_spec.rb
457
481
  - spec/routes/admin_spec.rb
458
- - spec/routes/app_spec.rb
459
482
  - spec/routes/auth_spec.rb
460
483
  - spec/routes/oauth_spec.rb
461
484
  - spec/spec_helper.rb
@@ -466,6 +489,7 @@ files:
466
489
  - spec/support/views/hosted_login.erb
467
490
  - spec/support/views/layout.erb
468
491
  - spec/support/views/multiple_providers.erb
492
+ - spec/support/views/saml_login_form.erb
469
493
  homepage: https://github.com/enterprise-oss/osso-rb
470
494
  licenses:
471
495
  - MIT
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'App' do
6
- end