Fixed issue with ldap images (#926)

This commit is contained in:
Ahmad Farhat 2020-01-22 16:39:29 -05:00 committed by farhatahmad
parent 005ec84c73
commit 8a8eee52fe
2 changed files with 48 additions and 0 deletions

View File

@ -48,6 +48,9 @@ module AuthValues
case auth['provider'] case auth['provider']
when :twitter when :twitter
auth['info']['image'].gsub("http", "https").gsub("_normal", "") auth['info']['image'].gsub("http", "https").gsub("_normal", "")
when :ldap
return auth['info']['image'] if auth['info']['image']&.starts_with?("http")
""
else else
auth['info']['image'] auth['info']['image']
end end

View File

@ -532,6 +532,51 @@ describe SessionsController, type: :controller do
expect(@request.session[:user_id]).to eql(u.id) expect(@request.session[:user_id]).to eql(u.id)
end end
it "should defaults the users image to blank if actual image is provided" do
entry = Net::LDAP::Entry.new("cn=Test User,ou=people,dc=planetexpress,dc=com")
entry[:cn] = "Test User"
entry[:givenName] = "Test"
entry[:sn] = "User"
entry[:mail] = "test@example.com"
entry[:jpegPhoto] = "\FF\F8" # Pretend image
allow_any_instance_of(Net::LDAP).to receive(:bind_as).and_return([entry])
post :ldap, params: {
session: {
user: "test",
password: 'password',
},
}
u = User.last
expect(u.provider).to eql("ldap")
expect(u.image).to eql("")
expect(@request.session[:user_id]).to eql(u.id)
end
it "uses the users image if a url is provided" do
image = Faker::Internet.url
entry = Net::LDAP::Entry.new("cn=Test User,ou=people,dc=planetexpress,dc=com")
entry[:cn] = "Test User"
entry[:givenName] = "Test"
entry[:sn] = "User"
entry[:mail] = "test@example.com"
entry[:jpegPhoto] = image
allow_any_instance_of(Net::LDAP).to receive(:bind_as).and_return([entry])
post :ldap, params: {
session: {
user: "test",
password: 'password',
},
}
u = User.last
expect(u.provider).to eql("ldap")
expect(u.image).to eql(image)
expect(@request.session[:user_id]).to eql(u.id)
end
it "should redirect to signin on invalid credentials" do it "should redirect to signin on invalid credentials" do
allow_any_instance_of(Net::LDAP).to receive(:bind_as).and_return(false) allow_any_instance_of(Net::LDAP).to receive(:bind_as).and_return(false)