summaryrefslogtreecommitdiff
path: root/spec/requests/api/ldap_spec.rb
blob: 8477a73ec34ed61e30bc9954619c514c308ee301 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'spec_helper'

describe API::API do
  include ApiHelpers
  let(:user) { create(:user) }

  before do
    groups = [
      OpenStruct.new(cn: 'developers'),
      OpenStruct.new(cn: 'students')
    ]

    allow_any_instance_of(Gitlab::LDAP::Adapter).to receive_messages(groups: groups)
  end

  describe "GET /ldap/groups" do
    context "when unauthenticated" do
      it "should return authentication error" do
        get api("/ldap/groups")
        expect(response.status).to eq 401
      end
    end

    context "when authenticated as user" do
      it "should return an array of ldap groups" do
        get api("/ldap/groups", user)
        expect(response.status).to eq 200
        expect(json_response).to be_an Array
        expect(json_response.length).to eq 2
        expect(json_response.first['cn']).to eq 'developers'
      end
    end
  end

  describe "GET /ldap/ldapmain/groups" do
    context "when unauthenticated" do
      it "should return authentication error" do
        get api("/ldap/ldapmain/groups")
        expect(response.status).to eq 401
      end
    end

    context "when authenticated as user" do
      it "should return an array of ldap groups" do
        get api("/ldap/ldapmain/groups", user)
        expect(response.status).to eq 200
        expect(json_response).to be_an Array
        expect(json_response.length).to eq 2
        expect(json_response.first['cn']).to eq 'developers'
      end
    end
  end
end