Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor LDAP user store tests #185

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions auth-ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,8 @@ task startLdapServer() {
}
if (!stdOut.toString().contains("openldap-server")) {
println "Starting LDAP server."
copy {
from file("$project.projectDir/tests/resources/openldap")
into file("/tmp")
}
exec {
commandLine 'sh', '-c', "docker run --rm -d -p 389:389 -p 636:636 --name openldap-server " +
"--env LDAP_ORGANISATION=\"AVIX\" " +
"--env LDAP_DOMAIN=\"avix.lk\" " +
"--env LDAP_ADMIN_PASSWORD=\"avix123\" " +
"--env LDAP_BASE_DN=\"dc=avix,dc=lk\" " +
"--volume /tmp/bootstrap.ldif:/container/service/slapd/assets/config/bootstrap/ldif/custom/bootstrap.ldif osixia/openldap:1.3.0 " +
"--copy-service"
commandLine 'sh', '-c', "docker-compose -f $project.projectDir/tests/resources/openldap/docker-compose.yml up -d"
standardOutput = stdOut
}
println stdOut.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ isolated function testLdapAuthenticationOfInvalidPassword() {
groups: ["ldap"]
}
isolated function testLdapAuthenticationSuccessForUser() {
string usernameAndPassword = "alice:alice123";
string usernameAndPassword = "alice:alice@123";
ListenerLdapUserStoreBasicAuthProvider basicAuthProvider = new(getLdapUserStoreConfig());
string credential = usernameAndPassword.toBytes().toBase64();
UserDetails|Error result = basicAuthProvider.authenticate(credential);
if (result is UserDetails) {
test:assertEquals(result.username, "alice");
test:assertEquals(result?.scopes, ["Developer"]);
test:assertEquals(result?.scopes, ["developer"]);
} else {
test:assertFail(msg = "Test Failed!");
}
Expand All @@ -165,13 +165,13 @@ isolated function testLdapAuthenticationSuccessForUser() {
groups: ["ldap"]
}
isolated function testLdapAuthenticationSuccessForSuperUser() {
string usernameAndPassword = "ldclakmal:ldclakmal123";
string usernameAndPassword = "ldclakmal:ldclakmal@123";
ListenerLdapUserStoreBasicAuthProvider basicAuthProvider = new(getLdapUserStoreConfig());
string credential = usernameAndPassword.toBytes().toBase64();
UserDetails|Error result = basicAuthProvider.authenticate(credential);
if (result is UserDetails) {
test:assertEquals(result.username, "ldclakmal");
test:assertEquals(result?.scopes, ["Admin", "Developer"]);
test:assertEquals(result?.scopes, ["admin", "developer"]);
} else {
test:assertFail(msg = "Test Failed!");
}
Expand Down
12 changes: 6 additions & 6 deletions auth-ballerina/tests/resources/openldap/bootstrap.ldif
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sn: Lakmal
uid: ldclakmal
displayName: Chanaka Lakmal
mail: ldclakmal@gmail.com
userpassword: ldclakmal123
userpassword: ldclakmal@123

dn: uid=alice,ou=Users,dc=avix,dc=lk
changetype: add
Expand All @@ -28,17 +28,17 @@ sn: Parker
uid: alice
displayName: Alice Parker
mail: alice@gmail.com
userpassword: alice123
userpassword: alice@123

dn: cn=Admin,ou=Groups,dc=avix,dc=lk
dn: cn=admin,ou=Groups,dc=avix,dc=lk
changetype: add
cn: Admin
cn: admin
objectClass: groupOfNames
member: uid=ldclakmal,ou=Users,dc=avix,dc=lk

dn: cn=Developer,ou=Groups,dc=avix,dc=lk
dn: cn=developer,ou=Groups,dc=avix,dc=lk
changetype: add
cn: Developer
cn: developer
objectClass: groupOfNames
member: uid=ldclakmal,ou=Users,dc=avix,dc=lk
member: uid=alice,ou=Users,dc=avix,dc=lk
16 changes: 16 additions & 0 deletions auth-ballerina/tests/resources/openldap/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.7'
services:
ldap_server:
image: osixia/openldap:1.3.0
container_name: openldap-server
environment:
LDAP_ORGANISATION: AVIX
LDAP_DOMAIN: avix.lk
LDAP_ADMIN_PASSWORD: avix123
LDAP_BASE_DN: dc=avix,dc=lk
ports:
- 389:389
- 636:636
volumes:
- ./bootstrap.ldif:/container/service/slapd/assets/config/bootstrap/ldif/custom/bootstrap.ldif
command: --copy-service