From 87bb3118f8a2d1944cc16b7f635d8213fa6396d9 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Fri, 29 Jul 2022 18:18:13 +0200 Subject: [PATCH] LDEV-4117 switch to rroemhild/test-openldap for build --- .github/workflows/main.yml | 15 +-- test/_setupTestServices.cfc | 7 +- test/tags/LDAP.cfc | 208 +++++++++++++++++------------------- 3 files changed, 113 insertions(+), 117 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1cac1ea6e..0ab9e62fb8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,10 +60,11 @@ jobs: - 3995:3995 #POP3S - 8080:8080 #API ldap: - image: kwart/ldap-server - ports: - - 10389:10389 - - 10636:10636 + # image: kwart/ldap-server + image: rroemhild/test-openldap + ports: + - 10389:10389 + - 10636:10636 steps: # when workflow is run via a workflow_call, these vars are found under input, which doesn't exist otherwise # so lets copy them over to the normal env vars @@ -178,9 +179,9 @@ jobs: POP_PASSWORD: doesntmatter LDAP_SERVER: localhost LDAP_PORT: 10389 - LDAP_BASE_DN: dc=example - LDAP_USERNAME: uid=jduke,ou=Users,dc=ldap,dc=example - # LDAP_PASSWORD: theduke + LDAP_BASE_DN: dc=planetexpress,dc=com + LDAP_USERNAME: cn=admin,dc=planetexpress,dc=com + LDAP_PASSWORD: GoodNewsEveryone S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_ID_TEST }} S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY_TEST }} # DO_DEPLOY: ${{ github.event_name == 'push' }} diff --git a/test/_setupTestServices.cfc b/test/_setupTestServices.cfc index 33ddec37bc..2f644354c5 100644 --- a/test/_setupTestServices.cfc +++ b/test/_setupTestServices.cfc @@ -228,7 +228,7 @@ component { server.test_services[arguments.service].valid = true; } catch (e) { systemOutput( "ERROR Service [ #arguments.service# ] threw [ #cfcatch.message# ]", true); - if ( cfcatch.message contains "NullPointerException" || request.testDebug ) + //if ( cfcatch.message contains "NullPointerException" || request.testDebug ) systemOutput(cfcatch, true); } } @@ -370,13 +370,14 @@ component { systemOutput( ldap, true ); cfldap( server=ldap.server, port=ldap.port, - timeout=5, + timeout=5000, username=ldap.username, password=ldap.password, action="query", name="local.results", start=ldap.base_dn, - attributes="cn,ou" ); + filter="(objectClass=inetOrgPerson)", + attributes="cn" ); systemOutput( results, true ); return "configured"; } diff --git a/test/tags/LDAP.cfc b/test/tags/LDAP.cfc index 5072cc1871..dd2f982b1d 100644 --- a/test/tags/LDAP.cfc +++ b/test/tags/LDAP.cfc @@ -1,5 +1,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="ldap" { + // uses docke image form docker pull rroemhild/test-openldap + public function beforeAll(){ variables.ldap = server.getTestService( "ldap" ); } @@ -11,149 +13,141 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="ldap" { function run( testResults, textbox ) { describe(title="checking CFLDAP tag", body = function( currentSpec ) { it(title="ldap action=query", skip=isDisabled(), body = function( currentSpec ) { - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="query", - name="local.results", - start=ldap.base_dn, - attributes="cn,ou" ); - systemOutput( results, true ); + // firstly do we have some data in LDAP + var results = ldapQuery( start=ldap.base_dn ); expect( results.recordcount ).toBeGT( 0 ); }); it (title="ldap action=modify", skip=isDisabled(), body = function( currentSpec ) { - // rename user - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="modify", - dn="uid=jduke,ou=Users,dc=ldap,dc=example", - name="local.results", - attributes="cn=Lucee Dev" ); + // create a user + ldapAdd( dn="uid=ralio,ou=people,#ldap.base_dn#", + attributes=ldapAddAttributes( cn="Ralio", sn="Fusion", uid="ralio" ) ); + + // update user + ldapUpdate( dn="uid=ralio,ou=people,#ldap.base_dn#", attributes="cn=Lucee Dev"); // check user is renamed - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="query", - name="local.results", - start=ldap.base_dn, - filter="uid=jduke", - attributes="cn,ou" ); - - systemOutput( results, true ); + var results = ldapQuery( start=ldap.base_dn, filter="(cn=Lucee Dev)" ); + expect( results.recordcount ).toBe( 1 ); expect( results.cn ).toBe( "Lucee Dev" ); - }); it (title="ldap action=modifyDN", skip=true, body = function( currentSpec ) { // add user - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="add", - dn="uid=ralio,ou=Users,dc=ldap,dc=example", - name="local.results", - attributes="cn=ralio" - ); + ldapAdd( dn="uid=cfml,ou=people,#ldap.base_dn#", + attributes=ldapAddAttributes( cn="Cold Fusion", sn="Fusion", uid="cfml" ) ); // check user exists - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="query", - name="local.results", - start=ldap.base_dn, - filter="uid=ralio", - attributes="cn,ou,uid"); - + var results = ldapQuery(start=ldap.base_dn, filter="(cn=cfml)"); expect( results.recordcount ).toBe( 1 ); - expect( results.cn ).toBe( "ralio" ); + expect( results.cn ).toBe( "Cold fusion" ); // rename user - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="modifyDN", - dn="uid=ralio,ou=Users,dc=ldap,dc=example", - name="local.results", - attributes="cn=Lucee" ); + ldapRename( dn="uid=cfml,ou=people,#ldap.base_dn#", attributes="cn=Lucee"); // check user is renamed - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="query", - name="local.results", - start=ldap.base_dn, - filter="uid=ralio", - attributes="cn,ou" ); - - systemOutput( results, true ); + var results = ldapQuery(start=ldap.base_dn, filter="(cn=Lucee)" ); expect( results.cn ).toBe( "Lucee" ); }); it (title="ldap action=add then delete", skip=isDisabled(), body = function( currentSpec ) { // add user - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="add", - dn="uid=lucee,ou=Users,dc=ldap,dc=example", - name="local.results", - attributes="cn=Lucee" - ); + ldapAdd( dn="uid=Lucee,ou=people,#ldap.base_dn#", + attributes=ldapAddAttributes( cn="Lucee", sn="6.0", uid="Lucee" ) ); // check user exists - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="query", - name="local.results", - start=ldap.base_dn, - filter="uid=lucee", - attributes="cn,ou,uid"); - + var results = ldapQuery(start=ldap.base_dn, filter="(cn=lucee)"); expect( results.recordcount ).toBe( 1 ); expect( results.cn ).toBe( "Lucee" ); // delete user - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="delete", - dn="uid=lucee,ou=Users,dc=ldap,dc=example", - name="local.results" - ); + ldapDelete( dn="uid=lucee,ou=people,#ldap.base_dn#" ); // check user no longer exists - cfldap( server=ldap.server, - port=ldap.port, - username=ldap.username, - password=ldap.password, - action="query", - name="local.results", - start=ldap.base_dn, - filter="uid=lucee", - attributes="cn,ou,uid"); - - systemOutput( results, true ); + var results = ldapQuery(start=ldap.base_dn, filter="(cn=lucee)"); expect( results.recordcount ).toBe( 0 ); }); }); } + private function ldapQuery( + string start=ldap.base_dn, + string filter="(objectClass=inetOrgPerson)", + string attributes="cn,ou,uid" ) { + cfldap( server=ldap.server, + port=ldap.port, + username=ldap.username, + password=ldap.password, + action="query", + name="local.results", + start=arguments.start, + filter=arguments.filter, + attributes=arguments.attributes); + // systemOutput( results, true ); + return results; + } + + private function ldapAdd( + required string dn, + required string attributes) { + cfldap( server=ldap.server, + port=ldap.port, + username=ldap.username, + password=ldap.password, + action="add", + dn=arguments.dn, + attributes=arguments.attributes + ); + + } + + private function ldapDelete( + required string dn ) { + cfldap( server=ldap.server, + port=ldap.port, + username=ldap.username, + password=ldap.password, + action="delete", + dn=arguments.dn + ); + } + + private function ldapRename( + required string dn, + required attributes ){ + cfldap( server=ldap.server, + port=ldap.port, + username=ldap.username, + password=ldap.password, + action="modifyDN", + dn=arguments.dn, + attributes=arguments.attributes + ); + } + + private function ldapUpdate( + required string dn, + required attributes ){ + cfldap( server=ldap.server, + port=ldap.port, + username=ldap.username, + password=ldap.password, + action="modify", + dn=arguments.dn, + attributes=arguments.attributes + ); + } + + private function ldapAddAttributes(cn, sn, uid){ + return "objectclass=inetOrgPerson;" + & "cn=#trim(arguments.cn)#;" + & "sn=#trim(arguments.sn)#;" + & "uid=#trim(arguments.uid)#"; + // mail=#Trim(Form.email)#; + // telephonenumber=#Trim(Form.phone)#; + // ou=Human Resources; + } + } \ No newline at end of file