Skip to content

Commit

Permalink
Refactor LDAP user store tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ldclakmal committed May 6, 2021
1 parent 643032e commit 9fa2924
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
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 -d $project.projectDir/tests/resources/openldap/docker-compose.yml up"
standardOutput = stdOut
}
println stdOut.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ 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);
Expand All @@ -165,7 +165,7 @@ 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);
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

0 comments on commit 9fa2924

Please sign in to comment.