osso 0.0.3.2 → 0.0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.buildkite/pipeline.yml +4 -1
  3. data/.rubocop.yml +1 -2
  4. data/Gemfile.lock +3 -1
  5. data/bin/console +4 -3
  6. data/config/database.yml +2 -2
  7. data/db/schema.rb +133 -1
  8. data/lib/osso.rb +2 -0
  9. data/lib/osso/db/migrate/20200328143305_create_identity_providers.rb +12 -0
  10. data/lib/osso/db/migrate/20200411184535_add_provider_id_to_users.rb +2 -2
  11. data/lib/osso/db/migrate/20200411192645_create_enterprise_accounts.rb +1 -1
  12. data/lib/osso/db/migrate/20200502135008_add_oauth_client_id_to_enterprise_accounts_and_identity_providers.rb +6 -0
  13. data/lib/osso/db/migrate/20200714223226_add_identity_provider_service_enum.rb +17 -0
  14. data/lib/osso/db/migrate/20200715154211_rename_idp_fields_on_identity_provider_to_sso.rb +6 -0
  15. data/lib/osso/db/migrate/20200715205801_add_name_to_enterprise_account.rb +5 -0
  16. data/lib/osso/graphql/mutation.rb +10 -5
  17. data/lib/osso/graphql/mutations.rb +5 -2
  18. data/lib/osso/graphql/mutations/base_mutation.rb +35 -14
  19. data/lib/osso/graphql/mutations/configure_identity_provider.rb +31 -21
  20. data/lib/osso/graphql/mutations/create_enterprise_account.rb +25 -0
  21. data/lib/osso/graphql/mutations/create_identity_provider.rb +22 -16
  22. data/lib/osso/graphql/mutations/set_identity_provider.rb +27 -0
  23. data/lib/osso/graphql/query.rb +19 -22
  24. data/lib/osso/graphql/resolvers.rb +5 -1
  25. data/lib/osso/graphql/resolvers/enterprise_account.rb +16 -12
  26. data/lib/osso/graphql/resolvers/enterprise_accounts.rb +10 -6
  27. data/lib/osso/graphql/resolvers/oauth_clients.rb +9 -5
  28. data/lib/osso/graphql/schema.rb +27 -19
  29. data/lib/osso/graphql/types.rb +4 -1
  30. data/lib/osso/graphql/types/base_enum.rb +6 -2
  31. data/lib/osso/graphql/types/base_input_object.rb +10 -0
  32. data/lib/osso/graphql/types/base_object.rb +6 -2
  33. data/lib/osso/graphql/types/enterprise_account.rb +22 -18
  34. data/lib/osso/graphql/types/identity_provider.rb +26 -25
  35. data/lib/osso/graphql/types/identity_provider_service.rb +8 -4
  36. data/lib/osso/graphql/types/oauth_client.rb +13 -9
  37. data/lib/osso/graphql/types/user.rb +10 -5
  38. data/lib/osso/helpers/auth.rb +5 -3
  39. data/lib/osso/lib/app_config.rb +1 -1
  40. data/lib/osso/lib/route_map.rb +28 -0
  41. data/lib/osso/models/enterprise_account.rb +4 -4
  42. data/lib/osso/models/identity_provider.rb +48 -0
  43. data/lib/osso/models/models.rb +1 -1
  44. data/lib/osso/models/oauth_client.rb +2 -2
  45. data/lib/osso/models/saml_provider.rb +13 -16
  46. data/lib/osso/models/saml_providers/azure_saml_provider.rb +2 -2
  47. data/lib/osso/models/saml_providers/okta_saml_provider.rb +1 -1
  48. data/lib/osso/models/user.rb +3 -3
  49. data/lib/osso/routes/admin.rb +18 -15
  50. data/lib/osso/routes/auth.rb +30 -27
  51. data/lib/osso/routes/oauth.rb +50 -45
  52. data/lib/osso/version.rb +1 -1
  53. data/osso-rb.gemspec +3 -3
  54. data/spec/factories/enterprise_account.rb +5 -4
  55. data/spec/factories/identity_providers.rb +49 -0
  56. data/spec/factories/user.rb +1 -1
  57. data/spec/graphql/mutations/configure_identity_provider_spec.rb +75 -0
  58. data/spec/graphql/mutations/create_enterprise_account_spec.rb +68 -0
  59. data/spec/graphql/mutations/create_identity_provider_spec.rb +104 -0
  60. data/spec/graphql/query/enterprise_account_spec.rb +68 -0
  61. data/spec/graphql/query/enterprise_accounts_spec.rb +44 -0
  62. data/spec/graphql/query/identity_provider_spec.rb +65 -0
  63. data/spec/graphql/query/oauth_clients_account_spec.rb +48 -0
  64. data/spec/models/azure_saml_provider_spec.rb +14 -14
  65. data/spec/models/identity_provider_spec.rb +17 -0
  66. data/spec/models/okta_saml_provider_spec.rb +15 -15
  67. data/spec/routes/admin_spec.rb +2 -0
  68. data/spec/routes/auth_spec.rb +9 -9
  69. data/spec/routes/oauth_spec.rb +1 -1
  70. data/spec/spec_helper.rb +4 -5
  71. data/spec/support/spec_app.rb +9 -0
  72. data/spec/support/views/admin.erb +5 -0
  73. metadata +37 -12
  74. data/lib/osso/db/migrate/20200411144528_create_saml_providers.rb +0 -13
  75. data/lib/osso/db/migrate/20200413153029_add_oauth_client_reference_to_saml_providers.rb +0 -5
  76. data/lib/osso/db/migrate/20200501203026_drop_null_constraints_from_saml_provider.rb +0 -7
  77. data/lib/osso/db/migrate/20200501204047_drop_acs_url.rb +0 -5
  78. data/lib/osso/db/migrate/20200502135008_add_oauth_client_id_to_enterprise_account.rb +0 -5
  79. data/lib/osso/db/migrate/20200601131227_drop_null_constraint_from_saml_providers_provider.rb +0 -7
  80. data/lib/osso/db/schema.rb +0 -132
  81. data/lib/osso/graphql/mutations/set_saml_provider.rb +0 -23
  82. data/spec/factories/saml_providers.rb +0 -46
  83. data/spec/models/saml_provider_spec.rb +0 -31
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Osso
4
+ module GraphQL
5
+ module Mutations
6
+ class CreateEnterpriseAccount < BaseMutation
7
+ null false
8
+
9
+ argument :domain, String, required: true
10
+ argument :name, String, required: true
11
+
12
+ field :enterprise_account, Types::EnterpriseAccount, null: false
13
+ field :errors, [String], null: false
14
+
15
+ def resolve(**args)
16
+ enterprise_account = Osso::Models::EnterpriseAccount.new(args)
17
+
18
+ return response_data(enterprise_account: enterprise_account) if enterprise_account.save
19
+
20
+ response_error(errors: enterprise_account.errors.full_messages)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,24 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Mutations
4
- class CreateIdentityProvider < BaseMutation
5
- null false
6
- argument :enterprise_account_id, ID, required: true
7
- argument :provider_service, Types::IdentityProviderService, required: true
3
+ module Osso
4
+ module GraphQL
5
+ module Mutations
6
+ class CreateIdentityProvider < BaseMutation
7
+ null false
8
8
 
9
- field :identity_provider, Types::IdentityProvider, null: false
10
- field :errors, [String], null: false
9
+ argument :enterprise_account_id, ID, required: true
10
+ argument :service, Types::IdentityProviderService, required: false
11
11
 
12
- def resolve(enterprise_account_id:, provider_service:)
13
- enterprise_account = Osso::Models::EnterpriseAccount.find(enterprise_account_id)
14
- identity_provider = enterprise_account.saml_providers.create!(
15
- provider: provider_service || 'OKTA',
16
- domain: enterprise_account.domain,
17
- )
12
+ field :identity_provider, Types::IdentityProvider, null: false
13
+ field :errors, [String], null: false
18
14
 
19
- return_data(identity_provider: identity_provider)
20
- rescue StandardError => e
21
- return_error(errors: e.full_message)
15
+ def resolve(enterprise_account_id:, service: nil)
16
+ enterprise_account = Osso::Models::EnterpriseAccount.find(enterprise_account_id)
17
+ identity_provider = enterprise_account.identity_providers.build(
18
+ enterprise_account_id: enterprise_account_id,
19
+ service: service,
20
+ domain: enterprise_account.domain,
21
+ )
22
+
23
+ return response_data(identity_provider: identity_provider) if identity_provider.save
24
+
25
+ response_error(errors: identity_provider.errors.full_messages)
26
+ end
27
+ end
22
28
  end
23
29
  end
24
30
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Osso
4
+ module GraphQL
5
+ module Mutations
6
+ class SetSamlProvider < BaseMutation
7
+ null false
8
+
9
+ argument :provider, Types::IdentityProviderService, required: true
10
+ argument :id, ID, required: true
11
+
12
+ field :identity_provider, Types::IdentityProvider, null: false
13
+ field :errors, [String], null: false
14
+
15
+ def resolve(provider:, id:)
16
+ identity_provider = Osso::Models::IdentityProvider.find(id)
17
+ identity_provider.service = provider
18
+ identity_provider.save!
19
+ {
20
+ identity_provider: identity_provider,
21
+ errors: [],
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,28 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Types
4
- class QueryType < GraphQL::Schema::Object
5
- # field :node, field: GraphQL::Relay::Node.field
6
- field :enterprise_account, null: false, resolver: Resolvers::EnterpriseAccount do
7
- argument :domain, String, required: true
8
- end
9
- field :enterprise_accounts, null: true, resolver: Resolvers::EnterpriseAccounts
10
- field :oauth_clients, null: true, resolver: Resolvers::OAuthClients
3
+ module Osso
4
+ module GraphQL
5
+ module Types
6
+ class QueryType < ::GraphQL::Schema::Object
7
+ field :enterprise_accounts, null: true, resolver: Resolvers::EnterpriseAccounts
8
+ field :oauth_clients, null: true, resolver: Resolvers::OAuthClients
11
9
 
12
- field(
13
- :identity_provider,
14
- Types::IdentityProvider,
15
- null: true,
16
- resolve: ->(_obj, args, _context) { Osso::Models::SamlProvider.find(args[:id]) },
17
- ) do
18
- argument :id, ID, required: true
19
- end
10
+ field :enterprise_account, null: true, resolver: Resolvers::EnterpriseAccount do
11
+ argument :domain, String, required: true
12
+ end
20
13
 
21
- # field(
22
- # :viewer,
23
- # Types::User,
24
- # null: true,
25
- # resolve: ->(_obj, _args, context) { context[:current_user] },
26
- # )
14
+ field(
15
+ :identity_provider,
16
+ Types::IdentityProvider,
17
+ null: true,
18
+ resolve: ->(_obj, args, _context) { Osso::Models::IdentityProvider.find(args[:id]) },
19
+ ) do
20
+ argument :id, ID, required: true
21
+ end
22
+ end
23
+ end
27
24
  end
28
25
  end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Resolvers
3
+ module Osso
4
+ module GraphQL
5
+ module Resolvers
6
+ end
7
+ end
4
8
  end
5
9
 
6
10
  require_relative 'resolvers/enterprise_account'
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Resolvers
4
- class EnterpriseAccount < GraphQL::Schema::Resolver
5
- type Types::EnterpriseAccount, null: false
3
+ module Osso
4
+ module GraphQL
5
+ module Resolvers
6
+ class EnterpriseAccount < ::GraphQL::Schema::Resolver
7
+ type Types::EnterpriseAccount, null: false
6
8
 
7
- def resolve(args)
8
- return unless admin? || enterprise_authorized?(args[:domain])
9
+ def resolve(args)
10
+ return unless admin? || enterprise_authorized?(args[:domain])
9
11
 
10
- Osso::Models::EnterpriseAccount.find_by(domain: args[:domain])
11
- end
12
+ Osso::Models::EnterpriseAccount.find_by(domain: args[:domain])
13
+ end
12
14
 
13
- def admin?
14
- context[:scope] == :admin
15
- end
15
+ def admin?
16
+ context[:scope] == :admin
17
+ end
16
18
 
17
- def enterprise_authorized?(domain)
18
- context[:scope] == domain
19
+ def enterprise_authorized?(domain)
20
+ context[:scope] == domain
21
+ end
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Resolvers
4
- class EnterpriseAccounts < GraphQL::Schema::Resolver
5
- type [Types::EnterpriseAccount], null: true
3
+ module Osso
4
+ module GraphQL
5
+ module Resolvers
6
+ class EnterpriseAccounts < ::GraphQL::Schema::Resolver
7
+ type [Types::EnterpriseAccount], null: true
6
8
 
7
- def resolve
8
- return Osso::Models::EnterpriseAccount.all if context[:scope] == :admin
9
+ def resolve
10
+ return Osso::Models::EnterpriseAccount.all if context[:scope] == :admin
9
11
 
10
- Array(Osso::Models::EnterpriseAccount.find_by(domain: context[:scope]))
12
+ Array(Osso::Models::EnterpriseAccount.find_by(domain: context[:scope]))
13
+ end
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Resolvers
4
- class OAuthClients < GraphQL::Schema::Resolver
5
- type [Types::OAuthClient], null: true
3
+ module Osso
4
+ module GraphQL
5
+ module Resolvers
6
+ class OAuthClients < ::GraphQL::Schema::Resolver
7
+ type [Types::OAuthClient], null: true
6
8
 
7
- def resolve
8
- return Osso::Models::OAuthClient.all if context[:scope] == :admin
9
+ def resolve
10
+ return Osso::Models::OauthClient.all if context[:scope] == :admin
11
+ end
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -11,28 +11,36 @@ GraphQL::Relay::BaseConnection.register_connection_implementation(
11
11
  GraphQL::Relay::RelationConnection,
12
12
  )
13
13
 
14
- class OssoSchema < GraphQL::Schema
15
- query Types::QueryType
16
- mutation Types::MutationType
17
- use GraphQL::Pagination::Connections
14
+ module Osso
15
+ module GraphQL
16
+ class Schema < ::GraphQL::Schema
17
+ use ::GraphQL::Pagination::Connections
18
+ query Types::QueryType
19
+ mutation Types::MutationType
18
20
 
19
- def self.id_from_object(object, _type_definition = nil, _query_ctx = nil)
20
- GraphQL::Schema::UniqueWithinType.encode(object.class.name, object.id)
21
- end
21
+ def self.id_from_object(object, _type_definition = nil, _query_ctx = nil)
22
+ GraphQL::Schema::UniqueWithinType.encode(object.class.name, object.id)
23
+ end
22
24
 
23
- def self.object_from_id(id, _query_ctx = nil)
24
- class_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
25
- Object.const_get(class_name).find(item_id)
26
- end
25
+ def self.object_from_id(id, _query_ctx = nil)
26
+ class_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
27
+ Object.const_get(class_name).find(item_id)
28
+ end
29
+
30
+ def self.resolve_type(_type, obj, _ctx)
31
+ case obj
32
+ when Osso::Models::EnterpriseAccount
33
+ Types::EnterpriseAccount
34
+ when Osso::Models::IdentityProvider
35
+ Types::IdentityProvider
36
+ else
37
+ raise("Unexpected object: #{obj}")
38
+ end
39
+ end
27
40
 
28
- def self.resolve_type(_type, obj, _ctx)
29
- case obj
30
- when Osso::Models::EnterpriseAccount
31
- Types::EnterpriseAccount
32
- when Osso::Models::SamlProvider
33
- Types::IdentityProvider
34
- else
35
- raise("Unexpected object: #{obj}")
41
+ def self.unauthorized_object(error)
42
+ raise ::GraphQL::ExecutionError, "An object of type #{error.type.graphql_name} was hidden due to permissions"
43
+ end
36
44
  end
37
45
  end
38
46
  end
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Types
3
+ module Osso
4
+ module Types
5
+ end
4
6
  end
5
7
 
6
8
  require_relative 'types/base_object'
7
9
  require_relative 'types/base_enum'
10
+ require_relative 'types/base_input_object'
8
11
  require_relative 'types/identity_provider_service'
9
12
  require_relative 'types/identity_provider'
10
13
  require_relative 'types/enterprise_account'
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Types
4
- class BaseEnum < GraphQL::Schema::Enum
3
+ module Osso
4
+ module GraphQL
5
+ module Types
6
+ class BaseEnum < ::GraphQL::Schema::Enum
7
+ end
8
+ end
5
9
  end
6
10
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Osso
4
+ module GraphQL
5
+ module Types
6
+ class BaseInputObject < ::GraphQL::Schema::InputObject
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,7 +2,11 @@
2
2
 
3
3
  require 'graphql'
4
4
 
5
- module Types
6
- class BaseObject < GraphQL::Schema::Object
5
+ module Osso
6
+ module GraphQL
7
+ module Types
8
+ class BaseObject < ::GraphQL::Schema::Object
9
+ end
10
+ end
7
11
  end
8
12
  end
@@ -2,28 +2,32 @@
2
2
 
3
3
  require 'graphql'
4
4
 
5
- module Types
6
- class EnterpriseAccount < Types::BaseObject
7
- description 'An Account for a company that wishes to use SAML via Osso'
8
- implements GraphQL::Types::Relay::Node
5
+ module Osso
6
+ module GraphQL
7
+ module Types
8
+ class EnterpriseAccount < Types::BaseObject
9
+ description 'An Account for a company that wishes to use SAML via Osso'
10
+ implements ::GraphQL::Types::Relay::Node
9
11
 
10
- global_id_field :gid
11
- field :id, ID, null: false
12
- field :name, String, null: false
13
- field :domain, String, null: false
14
- field :identity_providers, [Types::IdentityProvider], null: true
15
- field :status, String, null: false
12
+ global_id_field :gid
13
+ field :id, ID, null: false
14
+ field :name, String, null: false
15
+ field :domain, String, null: false
16
+ field :identity_providers, [Types::IdentityProvider], null: true
17
+ field :status, String, null: false
16
18
 
17
- def name
18
- object.domain.gsub('.com', '')
19
- end
19
+ def status
20
+ 'active'
21
+ end
20
22
 
21
- def status
22
- 'active'
23
- end
23
+ def identity_providers
24
+ object.identity_providers
25
+ end
24
26
 
25
- def identity_providers
26
- object.saml_providers
27
+ def self.authorized?(object, context)
28
+ super && (context[:scope] == :admin || object.domain == context[:scope])
29
+ end
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -2,35 +2,36 @@
2
2
 
3
3
  require 'graphql'
4
4
 
5
- module Types
6
- class IdentityProvider < Types::BaseObject
7
- description 'Represents a SAML based IDP instance for an EnterpriseAccount'
8
- implements GraphQL::Types::Relay::Node
5
+ module Osso
6
+ module GraphQL
7
+ module Types
8
+ class IdentityProvider < Types::BaseObject
9
+ description 'Represents a SAML based IDP instance for an EnterpriseAccount'
10
+ implements ::GraphQL::Types::Relay::Node
9
11
 
10
- global_id_field :gid
11
- field :id, ID, null: false
12
- field :enterprise_Account_id, ID, null: false
13
- field :service, Types::IdentityProviderService, null: true
14
- field :domain, String, null: false
15
- field :acs_url, String, null: false
16
- field :sso_url, String, null: true
17
- field :sso_cert, String, null: true
18
- field :configured, Boolean, null: false
12
+ global_id_field :gid
13
+ field :id, ID, null: false
14
+ field :enterprise_account_id, ID, null: false
15
+ field :service, Types::IdentityProviderService, null: true
16
+ field :domain, String, null: false
17
+ field :acs_url, String, null: false
18
+ field :sso_url, String, null: true
19
+ field :sso_cert, String, null: true
20
+ field :configured, Boolean, null: false
21
+ field :documentation_pdf_url, String, null: true
19
22
 
20
- def service
21
- @object.provider
22
- end
23
-
24
- def configured
25
- @object.idp_sso_target_url && @object.idp_cert
26
- end
23
+ def configured
24
+ !!(@object.sso_url && @object.sso_cert)
25
+ end
27
26
 
28
- def sso_cert
29
- @object.idp_cert
30
- end
27
+ def documentation_pdf_url
28
+ ENV['BASE_URL'] + '/identity_provider/documentation/' + @object.id
29
+ end
31
30
 
32
- def sso_url
33
- @object.idp_sso_target_url
31
+ def self.authorized?(object, context)
32
+ super && (context[:scope] == :admin || object.domain == context[:scope])
33
+ end
34
+ end
34
35
  end
35
36
  end
36
37
  end