main
 1# frozen_string_literal: true
 2
 3RSpec.describe Scim::Kit::V2::Configuration do
 4  subject do
 5    described_class.new do |x|
 6      x.service_provider_configuration(location: sp_location) do |y|
 7        y.add_authentication(:oauthbearertoken)
 8        y.change_password.supported = true
 9      end
10      x.resource_type(id: 'User', location: user_type_location) do |y|
11        y.schema = Scim::Kit::V2::Schemas::USER
12      end
13      x.resource_type(id: 'Group', location: group_type_location) do |y|
14        y.schema = Scim::Kit::V2::Schemas::GROUP
15      end
16      x.schema(id: 'User', name: 'User', location: user_schema_location) do |y|
17        y.add_attribute(name: 'userName')
18      end
19    end
20  end
21
22  let(:sp_location) { FFaker::Internet.uri('https') }
23  let(:user_type_location) { FFaker::Internet.uri('https') }
24  let(:group_type_location) { FFaker::Internet.uri('https') }
25  let(:user_schema_location) { FFaker::Internet.uri('https') }
26
27  specify { expect(subject.service_provider_configuration.meta.location).to eql(sp_location) }
28  specify { expect(subject.service_provider_configuration.authentication_schemes[0].type).to be(:oauthbearertoken) }
29  specify { expect(subject.service_provider_configuration.change_password.supported).to be(true) }
30
31  specify { expect(subject.resource_types['User'].schema).to eql(Scim::Kit::V2::Schemas::USER) }
32  specify { expect(subject.resource_types['User'].id).to eql('User') }
33  specify { expect(subject.resource_types['Group'].schema).to eql(Scim::Kit::V2::Schemas::GROUP) }
34  specify { expect(subject.resource_types['Group'].id).to eql('Group') }
35
36  specify { expect(subject.schemas['User'].id).to eql('User') }
37  specify { expect(subject.schemas['User'].name).to eql('User') }
38  specify { expect(subject.schemas['User'].meta.location).to eql(user_schema_location) }
39  specify { expect(subject.schemas['User'].attributes[0].name).to eql('user_name') }
40
41  describe '#load_from' do
42    let(:base_url) { FFaker::Internet.uri('https') }
43    let(:service_provider_configuration) do
44      Scim::Kit::V2::ServiceProviderConfiguration.new(location: FFaker::Internet.uri('https'))
45    end
46    let(:schema) do
47      Scim::Kit::V2::Schema.new(id: 'User', name: 'User', location: FFaker::Internet.uri('https'))
48    end
49    let(:resource_type) do
50      x = Scim::Kit::V2::ResourceType.new(location: FFaker::Internet.uri('https'))
51      x.id = 'User'
52      x
53    end
54
55    before do
56      stub_request(:get, "#{base_url}/ServiceProviderConfig")
57        .to_return(status: 200, body: service_provider_configuration.to_json)
58
59      stub_request(:get, "#{base_url}/Schemas")
60        .to_return(status: 200, body: [schema.to_h].to_json)
61
62      stub_request(:get, "#{base_url}/ResourceTypes")
63        .to_return(status: 200, body: [resource_type.to_h].to_json)
64
65      subject.load_from(base_url)
66    end
67
68    specify { expect(subject.service_provider_configuration.to_h).to eql(service_provider_configuration.to_h) }
69    specify { expect(subject.schemas[schema.id].to_h).to eql(schema.to_h) }
70    specify { expect(subject.resource_types[resource_type.id].to_h).to eql(resource_type.to_h) }
71  end
72end