Add service attribute to LDAP user entry
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe User, type: :model do
|
||||
let(:user) { create :user }
|
||||
let(:user) { create :user, cn: "philipp" }
|
||||
let(:dn) { "cn=philipp,ou=kosmos.org,cn=users,dc=kosmos,dc=org" }
|
||||
|
||||
describe "#address" do
|
||||
let(:user) { build :user, cn: "jimmy", ou: "kosmos.org" }
|
||||
|
||||
it "returns the user address" do
|
||||
expect(user.address).to eq("jimmy@kosmos.org")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#is_admin?" do
|
||||
it "returns true when admin flag is set in LDAP" do
|
||||
@@ -21,11 +30,75 @@ RSpec.describe User, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#address" do
|
||||
let(:user) { build :user, cn: "jimmy", ou: "kosmos.org" }
|
||||
|
||||
it "returns the user address" do
|
||||
expect(user.address).to eq("jimmy@kosmos.org")
|
||||
describe "#services_enabled" do
|
||||
it "returns the entries from the LDAP service attribute" do
|
||||
expect(user).to receive(:ldap_entry).and_return({
|
||||
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
|
||||
service: ["discourse", "gitea", "wiki", "xmpp"]
|
||||
})
|
||||
expect(user.services_enabled).to eq(["discourse", "gitea", "wiki", "xmpp"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#enable_service" do
|
||||
before do
|
||||
allow(user).to receive(:ldap_entry).and_return({
|
||||
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
|
||||
service: ["discourse", "gitea"]
|
||||
})
|
||||
allow(user).to receive(:dn).and_return(dn)
|
||||
end
|
||||
|
||||
it "adds the service to the LDAP entry" do
|
||||
expect_any_instance_of(LdapService).to receive(:replace_attribute)
|
||||
.with(dn, :service, ["discourse", "gitea", "wiki"]).and_return(true)
|
||||
|
||||
user.enable_service(:wiki)
|
||||
end
|
||||
|
||||
it "adds multiple service to the LDAP entry" do
|
||||
expect_any_instance_of(LdapService).to receive(:replace_attribute)
|
||||
.with(dn, :service, ["discourse", "gitea", "wiki", "xmpp"]).and_return(true)
|
||||
|
||||
user.enable_service([:wiki, :xmpp])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#disable_service" do
|
||||
before do
|
||||
allow(user).to receive(:ldap_entry).and_return({
|
||||
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
|
||||
service: ["discourse", "gitea", "xmpp"]
|
||||
})
|
||||
allow(user).to receive(:dn).and_return(dn)
|
||||
end
|
||||
|
||||
it "removes the service from the LDAP entry" do
|
||||
expect_any_instance_of(LdapService).to receive(:replace_attribute)
|
||||
.with(dn, :service, ["discourse", "gitea"]).and_return(true)
|
||||
|
||||
user.disable_service(:xmpp)
|
||||
end
|
||||
|
||||
it "removes multiple services from the LDAP entry" do
|
||||
expect_any_instance_of(LdapService).to receive(:replace_attribute)
|
||||
.with(dn, :service, ["discourse"]).and_return(true)
|
||||
|
||||
user.disable_service([:xmpp, "gitea"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#disable_all_services" do
|
||||
before do
|
||||
allow(user).to receive(:dn).and_return(dn)
|
||||
end
|
||||
|
||||
it "removes all services from the LDAP entry" do
|
||||
expect_any_instance_of(LdapService).to receive(:delete_attribute)
|
||||
.with(dn, :service).and_return(true)
|
||||
|
||||
user.disable_all_services
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user