Sha256: ed2f60d2975c181e3fb90fc31425f381ae5763d62594a5542ab10cbecd6f2d64

Contents?: true

Size: 1.82 KB

Versions: 9

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Scimaenaga::ScimGroupsController, type: :request do
  let(:company) { create(:company) }
  let(:credentials) do
    Base64.encode64("#{company.subdomain}:#{company.api_token}")
  end
  let(:authorization) { "Basic #{credentials}" }

  def post_request(content_type = 'application/scim+json')
    post '/scim/v2/Groups',
         params: {
           displayName: 'Dummy Group',
           members: [],
         }.to_json,
         headers: {
           Authorization: authorization,
           'Content-Type': content_type,
         }
  end

  describe 'Content-Type' do
    it 'accepts scim+json' do
      expect(company.groups.count).to eq 0

      post_request('application/scim+json')

      expect(request.params).to include :displayName
      expect(response.status).to eq 201
      expect(response.media_type).to eq 'application/scim+json'
      expect(company.groups.count).to eq 1
    end

    it 'can not parse unfamiliar content types' do
      expect(company.groups.count).to eq 0

      post_request('text/csv')

      expect(request.params).not_to include :displayName
      expect(response.status).to eq 422
      expect(company.groups.count).to eq 0
    end
  end

  context 'OAuth Bearer Authorization' do
    context 'with valid token' do
      let(:authorization) { "Bearer #{company.api_token}" }

      it 'supports OAuth bearer authorization and succeeds' do
        expect { post_request }.to change(company.groups, :count).from(0).to(1)

        expect(response.status).to eq 201
      end
    end

    context 'with invalid token' do
      let(:authorization) { "Bearer #{SecureRandom.hex}" }

      it 'The request fails' do
        expect { post_request }.not_to change(company.groups, :count)

        expect(response.status).to eq 401
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
scimaenaga-1.0.5 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-1.0.4 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-1.0.3 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-1.0.2 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-1.0.1 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-1.0.0 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-0.9.3 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-0.9.2 spec/controllers/scimaenaga/scim_groups_request_spec.rb
scimaenaga-0.9.1 spec/controllers/scimaenaga/scim_groups_request_spec.rb