osso 0.0.8 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e32f4645ca2763467c9558a6bf103cc5695de99b191e0e2a763e9d1be189e984
4
- data.tar.gz: ca9c4d902553eee5132fc41c98a458441b20c6aa645bc8a33b48601c80e83392
3
+ metadata.gz: 59118bc5190af82cb537d0e2bd6446651382fe049554a9ec284c10d227a8e2bc
4
+ data.tar.gz: 6388744bb74e905ac5c742aba1062edf6f9d2b518bc7484dc017286632ceb317
5
5
  SHA512:
6
- metadata.gz: 1c58936f2fa400fb36955405512522bb1fb25ca3c6d8c3436b157d7d915e4db662070b93e1f6f6c7cb523d6f90043426b7bb8b6320967e09aac3be536587c840
7
- data.tar.gz: '0359da56b5e70537d496a770d6f4e90a1ec248bc786e48b7a7f13dd3860729cb5d1a76de43a9666a486ad4727f3c032c22bdf0a4c0257ee3416d5d41164295c3'
6
+ metadata.gz: a14dd7a884f56ce1a420ee85bd04690f933538f9c5a9cad5c89a925f955130e27d29b6007e9670e9252f445d8fc6d104f97a80394ada11827accce8334b2d449
7
+ data.tar.gz: b9168f801d70b7d78cb7c4495a69a702fe5ca05689eb093442396db46f6877c935f621907bfddea4ad5770b220c135bb4f0f3620ff0e2c2d8e790402eb268c46
@@ -12,6 +12,7 @@ steps:
12
12
  - coverage/*
13
13
 
14
14
  - name: ":codeclimate:"
15
+ soft_fail: true
15
16
  plugins:
16
17
  - jobready/codeclimate-test-reporter#v2.0:
17
18
  artifact: "coverage/.resultset.json"
data/.rubocop.yml CHANGED
@@ -1,25 +1,10 @@
1
1
  AllCops:
2
+ NewCops: enable
2
3
  TargetRubyVersion: 2.6.0
3
4
  Exclude:
4
5
  - db/**/*
5
6
  - lib/osso/db/**/*
6
7
 
7
- # New rules must be explicitly opted into / out of
8
- Lint/RaiseException:
9
- Enabled: true
10
- Lint/StructNewOverride:
11
- Enabled: true
12
- Style/HashEachMethods:
13
- Enabled: true
14
- Style/HashTransformKeys:
15
- Enabled: true
16
- Style/HashTransformValues:
17
- Enabled: true
18
- Layout/SpaceAroundMethodCallOperator:
19
- Enabled: true
20
- Style/ExponentialNotation:
21
- Enabled: true
22
-
23
8
  Style/TrailingCommaInArguments:
24
9
  Description: "Checks for trailing comma in argument lists."
25
10
  StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas"
@@ -50,6 +35,9 @@ Style/TrailingCommaInHashLiteral:
50
35
  - no_comma
51
36
  Enabled: true
52
37
 
38
+ Layout/FirstHashElementIndentation:
39
+ EnforcedStyle: consistent
40
+
53
41
  Layout/MultilineMethodCallIndentation:
54
42
  EnforcedStyle: indented
55
43
 
data/Gemfile CHANGED
@@ -12,8 +12,8 @@ group :test do
12
12
  gem 'rack-test'
13
13
  gem 'rspec', '~> 3.10'
14
14
  gem 'rubocop'
15
- gem 'simplecov', '= 0.17', require: false
16
- gem 'webmock', '~> 3.10'
15
+ gem 'simplecov', '0.21.2', require: false
16
+ gem 'webmock', '~> 3.11'
17
17
  end
18
18
 
19
19
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- osso (0.0.8)
4
+ osso (0.1.2)
5
5
  activesupport (>= 6.0.3.2)
6
6
  bcrypt (~> 3.1.13)
7
7
  graphql
@@ -9,26 +9,28 @@ PATH
9
9
  mail (~> 2.7.1)
10
10
  omniauth-multi-provider
11
11
  omniauth-saml
12
+ posthog-ruby
12
13
  rack (>= 2.1.4)
13
14
  rack-contrib
14
15
  rack-oauth2
16
+ rack-protection (~> 2.1.0)
15
17
  rake
16
- rodauth (~> 2.6.0)
17
- sequel (>= 5.37, < 5.40)
18
+ rodauth (~> 2.9)
19
+ sequel (~> 5.40)
18
20
  sequel-activerecord_connection (>= 0.3, < 2.0)
19
21
  sinatra
20
- sinatra-activerecord
22
+ sinatra-activerecord (>= 2.0.22)
21
23
  sinatra-contrib
22
24
 
23
25
  GEM
24
26
  remote: https://rubygems.org/
25
27
  specs:
26
- activemodel (6.1.0)
27
- activesupport (= 6.1.0)
28
- activerecord (6.1.0)
29
- activemodel (= 6.1.0)
30
- activesupport (= 6.1.0)
31
- activesupport (6.1.0)
28
+ activemodel (6.1.1)
29
+ activesupport (= 6.1.1)
30
+ activerecord (6.1.1)
31
+ activemodel (= 6.1.1)
32
+ activesupport (= 6.1.1)
33
+ activesupport (6.1.1)
32
34
  concurrent-ruby (~> 1.0, >= 1.0.2)
33
35
  i18n (>= 1.6, < 2)
34
36
  minitest (>= 5.1)
@@ -42,30 +44,30 @@ GEM
42
44
  annotate (3.1.1)
43
45
  activerecord (>= 3.2, < 7.0)
44
46
  rake (>= 10.4, < 14.0)
45
- ast (2.4.1)
47
+ ast (2.4.2)
46
48
  attr_required (1.0.1)
47
49
  bcrypt (3.1.16)
48
50
  bindata (2.4.8)
49
51
  coderay (1.1.3)
50
- concurrent-ruby (1.1.7)
51
- crack (0.4.4)
52
- database_cleaner (1.8.5)
53
- database_cleaner-active_record (1.8.0)
54
- activerecord
55
- database_cleaner (~> 1.8.0)
52
+ concurrent-ruby (1.1.8)
53
+ crack (0.4.5)
54
+ rexml
55
+ database_cleaner-active_record (2.0.0)
56
+ activerecord (>= 5.a)
57
+ database_cleaner-core (~> 2.0.0)
58
+ database_cleaner-core (2.0.0)
56
59
  diff-lcs (1.4.4)
57
- docile (1.3.2)
60
+ docile (1.3.5)
58
61
  factory_bot (6.1.0)
59
62
  activesupport (>= 5.0.0)
60
63
  faker (2.15.1)
61
64
  i18n (>= 1.6, < 2)
62
- graphql (1.11.6)
65
+ graphql (1.12.3)
63
66
  hashdiff (1.0.1)
64
67
  hashie (4.1.0)
65
68
  httpclient (2.8.3)
66
- i18n (1.8.5)
69
+ i18n (1.8.7)
67
70
  concurrent-ruby (~> 1.0)
68
- json (2.3.1)
69
71
  json-jwt (1.13.0)
70
72
  activesupport (>= 4.2)
71
73
  aes_key_wrap
@@ -75,29 +77,31 @@ GEM
75
77
  mini_mime (>= 0.1.1)
76
78
  method_source (1.0.0)
77
79
  mini_mime (1.0.2)
78
- mini_portile2 (2.4.0)
79
- minitest (5.14.2)
80
+ minitest (5.14.3)
80
81
  multi_json (1.15.0)
81
82
  mustermann (1.1.1)
82
83
  ruby2_keywords (~> 0.0.1)
83
- nokogiri (1.10.10)
84
- mini_portile2 (~> 2.4.0)
85
- omniauth (1.9.1)
84
+ nokogiri (1.11.1-x86_64-darwin)
85
+ racc (~> 1.4)
86
+ omniauth (2.0.1)
86
87
  hashie (>= 3.4.6)
87
88
  rack (>= 1.6.2, < 3)
89
+ rack-protection
88
90
  omniauth-multi-provider (0.2.1)
89
91
  omniauth
90
- omniauth-saml (1.10.3)
91
- omniauth (~> 1.3, >= 1.3.2)
92
+ omniauth-saml (2.0.0)
93
+ omniauth (~> 2.0)
92
94
  ruby-saml (~> 1.9)
93
95
  parallel (1.20.1)
94
- parser (2.7.2.0)
96
+ parser (3.0.0.0)
95
97
  ast (~> 2.4.1)
96
98
  pg (1.2.3)
99
+ posthog-ruby (1.1.0)
97
100
  pry (0.13.1)
98
101
  coderay (~> 1.1)
99
102
  method_source (~> 1.0)
100
103
  public_suffix (4.0.6)
104
+ racc (1.5.2)
101
105
  rack (2.2.3)
102
106
  rack-contrib (2.3.0)
103
107
  rack (~> 2.0)
@@ -112,58 +116,59 @@ GEM
112
116
  rack-test (1.1.0)
113
117
  rack (>= 1.0, < 3)
114
118
  rainbow (3.0.0)
115
- rake (13.0.1)
116
- regexp_parser (2.0.0)
119
+ rake (13.0.3)
120
+ regexp_parser (2.0.3)
117
121
  rexml (3.2.4)
118
- roda (3.38.0)
122
+ roda (3.40.0)
119
123
  rack
120
- rodauth (2.6.0)
124
+ rodauth (2.9.0)
121
125
  roda (>= 2.6.0)
122
126
  sequel (>= 4)
123
127
  rspec (3.10.0)
124
128
  rspec-core (~> 3.10.0)
125
129
  rspec-expectations (~> 3.10.0)
126
130
  rspec-mocks (~> 3.10.0)
127
- rspec-core (3.10.0)
131
+ rspec-core (3.10.1)
128
132
  rspec-support (~> 3.10.0)
129
- rspec-expectations (3.10.0)
133
+ rspec-expectations (3.10.1)
130
134
  diff-lcs (>= 1.2.0, < 2.0)
131
135
  rspec-support (~> 3.10.0)
132
- rspec-mocks (3.10.0)
136
+ rspec-mocks (3.10.1)
133
137
  diff-lcs (>= 1.2.0, < 2.0)
134
138
  rspec-support (~> 3.10.0)
135
- rspec-support (3.10.0)
136
- rubocop (1.6.1)
139
+ rspec-support (3.10.1)
140
+ rubocop (1.9.0)
137
141
  parallel (~> 1.10)
138
- parser (>= 2.7.1.5)
142
+ parser (>= 3.0.0.0)
139
143
  rainbow (>= 2.2.2, < 4.0)
140
144
  regexp_parser (>= 1.8, < 3.0)
141
145
  rexml
142
146
  rubocop-ast (>= 1.2.0, < 2.0)
143
147
  ruby-progressbar (~> 1.7)
144
- unicode-display_width (>= 1.4.0, < 2.0)
145
- rubocop-ast (1.3.0)
148
+ unicode-display_width (>= 1.4.0, < 3.0)
149
+ rubocop-ast (1.4.1)
146
150
  parser (>= 2.7.1.5)
147
- ruby-progressbar (1.10.1)
151
+ ruby-progressbar (1.11.0)
148
152
  ruby-saml (1.11.0)
149
153
  nokogiri (>= 1.5.10)
150
- ruby2_keywords (0.0.2)
151
- sequel (5.39.0)
152
- sequel-activerecord_connection (1.2.0)
154
+ ruby2_keywords (0.0.4)
155
+ sequel (5.40.0)
156
+ sequel-activerecord_connection (1.2.2)
153
157
  activerecord (>= 4.2, < 7)
154
158
  after_commit_everywhere (~> 0.1.5)
155
159
  sequel (~> 5.16)
156
- simplecov (0.17.0)
160
+ simplecov (0.21.2)
157
161
  docile (~> 1.1)
158
- json (>= 1.8, < 3)
159
- simplecov-html (~> 0.10.0)
160
- simplecov-html (0.10.2)
162
+ simplecov-html (~> 0.11)
163
+ simplecov_json_formatter (~> 0.1)
164
+ simplecov-html (0.12.3)
165
+ simplecov_json_formatter (0.1.2)
161
166
  sinatra (2.1.0)
162
167
  mustermann (~> 1.0)
163
168
  rack (~> 2.2)
164
169
  rack-protection (= 2.1.0)
165
170
  tilt (~> 2.0)
166
- sinatra-activerecord (2.0.21)
171
+ sinatra-activerecord (2.0.22)
167
172
  activerecord (>= 4.1)
168
173
  sinatra (>= 1.0)
169
174
  sinatra-contrib (2.1.0)
@@ -173,10 +178,10 @@ GEM
173
178
  sinatra (= 2.1.0)
174
179
  tilt (~> 2.0)
175
180
  tilt (2.0.10)
176
- tzinfo (2.0.3)
181
+ tzinfo (2.0.4)
177
182
  concurrent-ruby (~> 1.0)
178
- unicode-display_width (1.7.0)
179
- webmock (3.10.0)
183
+ unicode-display_width (2.0.0)
184
+ webmock (3.11.2)
180
185
  addressable (>= 2.3.6)
181
186
  crack (>= 0.3.2)
182
187
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -197,8 +202,8 @@ DEPENDENCIES
197
202
  rack-test
198
203
  rspec (~> 3.10)
199
204
  rubocop
200
- simplecov (= 0.17)
201
- webmock (~> 3.10)
205
+ simplecov (= 0.21.2)
206
+ webmock (~> 3.11)
202
207
 
203
208
  BUNDLED WITH
204
209
  2.1.4
data/Rakefile CHANGED
@@ -5,6 +5,7 @@
5
5
  # schema and migrations
6
6
 
7
7
  ENV['SESSION_SECRET'] ||= 'rake-secret'
8
+ ENV['BASE_URL'] ||= 'https://example.com'
8
9
 
9
10
  require 'bundler/gem_tasks'
10
11
  require 'sinatra/activerecord/rake'
data/bin/console CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ ENV['SESSION_SECRET'] ||= 'irb-secret'
5
+ ENV['BASE_URL'] ||= 'https://example.com'
6
+
4
7
  require 'bundler/setup'
5
8
  require 'osso'
6
9
 
data/db/schema.rb CHANGED
@@ -2,15 +2,15 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2020_11_25_143501) do
13
+ ActiveRecord::Schema.define(version: 2021_02_01_220556) do
14
14
 
15
15
  # These are extensions that must be enabled in order to support this database
16
16
  enable_extension "citext"
@@ -57,7 +57,7 @@ ActiveRecord::Schema.define(version: 2020_11_25_143501) do
57
57
  t.citext "email", null: false
58
58
  t.integer "status_id", default: 1, null: false
59
59
  t.string "role", default: "admin", null: false
60
- t.string "oauth_client_id"
60
+ t.uuid "oauth_client_id"
61
61
  t.index ["email"], name: "index_accounts_on_email", unique: true, where: "(status_id = ANY (ARRAY[1, 2]))"
62
62
  t.index ["oauth_client_id"], name: "index_accounts_on_oauth_client_id"
63
63
  end
data/lib/osso.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Osso
4
4
  require_relative 'osso/error/error'
5
+ require_relative 'osso/lib/analytics'
5
6
  require_relative 'osso/lib/app_config'
6
7
  require_relative 'osso/lib/oauth2_token'
7
8
  require_relative 'osso/lib/route_map'
@@ -0,0 +1,28 @@
1
+ class AddGenericSamlToProviderServiceEnum < ActiveRecord::Migration[6.1]
2
+ disable_ddl_transaction!
3
+
4
+ def up
5
+ execute <<-SQL
6
+ ALTER TYPE identity_provider_service ADD VALUE 'OTHER';
7
+ SQL
8
+ end
9
+
10
+ def down
11
+ execute <<~SQL
12
+ CREATE TYPE identity_provider_service_new AS ENUM ('AZURE', 'OKTA', 'ONELOGIN', 'GOOGLE', 'PING', 'SALESFORCE');
13
+
14
+ -- Remove values that won't be compatible with new definition
15
+ DELETE FROM identity_providers WHERE service = 'OTHER';
16
+
17
+ -- Convert to new type, casting via text representation
18
+ ALTER TABLE identity_providers
19
+ ALTER COLUMN service TYPE identity_provider_service_new
20
+ USING (service::text::identity_provider_service_new);
21
+
22
+ -- and swap the types
23
+ DROP TYPE identity_provider_service;
24
+
25
+ ALTER TYPE identity_provider_service_new RENAME TO identity_provider_service;
26
+ SQL
27
+ end
28
+ end
@@ -15,7 +15,10 @@ module Osso
15
15
  def resolve(**args)
16
16
  provider = identity_provider(**args)
17
17
 
18
- return response_data(identity_provider: provider) if provider.update(args)
18
+ if provider.update(args)
19
+ Osso::Analytics.capture(email: context[:email], event: self.class.name.demodulize, properties: args)
20
+ return response_data(identity_provider: provider)
21
+ end
19
22
 
20
23
  response_error(provider.errors)
21
24
  end
@@ -15,7 +15,10 @@ module Osso
15
15
  def resolve(**args)
16
16
  enterprise_account = Osso::Models::EnterpriseAccount.new(args)
17
17
 
18
- return response_data(enterprise_account: enterprise_account) if enterprise_account.save
18
+ if enterprise_account.save
19
+ Osso::Analytics.capture(email: context[:email], event: self.class.name.demodulize, properties: args)
20
+ return response_data(enterprise_account: enterprise_account)
21
+ end
19
22
 
20
23
  response_error(enterprise_account.errors)
21
24
  end
@@ -13,7 +13,7 @@ module Osso
13
13
  field :identity_provider, Types::IdentityProvider, null: false
14
14
  field :errors, [String], null: false
15
15
 
16
- def resolve(service: nil, enterprise_account_id:, oauth_client_id:)
16
+ def resolve(enterprise_account_id:, oauth_client_id:, service: nil)
17
17
  customer = enterprise_account(enterprise_account_id: enterprise_account_id)
18
18
 
19
19
  identity_provider = customer.identity_providers.build(
@@ -22,12 +22,17 @@ module Osso
22
22
  oauth_client_id: oauth_client_id,
23
23
  )
24
24
 
25
- return response_data(identity_provider: identity_provider) if identity_provider.save
25
+ if identity_provider.save
26
+ Osso::Analytics.capture(email: context[:email], event: self.class.name.demodulize, properties: {
27
+ service: service, enterprise_account_id: enterprise_account_id, oauth_client_id: oauth_client_id
28
+ })
29
+ return response_data(identity_provider: identity_provider)
30
+ end
26
31
 
27
32
  response_error(identity_provider.errors)
28
33
  end
29
34
 
30
- def domain(enterprise_account_id:, **args)
35
+ def domain(enterprise_account_id:, **_args)
31
36
  enterprise_account(enterprise_account_id: enterprise_account_id)&.domain
32
37
  end
33
38
 
@@ -14,7 +14,10 @@ module Osso
14
14
  def resolve(**args)
15
15
  oauth_client = Osso::Models::OauthClient.new(args)
16
16
 
17
- return response_data(oauth_client: oauth_client) if oauth_client.save
17
+ if oauth_client.save
18
+ Osso::Analytics.capture(email: context[:email], event: self.class.name.demodulize, properties: args)
19
+ return response_data(oauth_client: oauth_client)
20
+ end
18
21
 
19
22
  response_error(oauth_client.errors)
20
23
  end