Skip to content

Commit 151bbb1

Browse files
test: Improve the ldap integration test
1 parent c812fff commit 151bbb1

6 files changed

Lines changed: 124 additions & 106 deletions

File tree

tests/templates/kuttl/ldap/10-install-openldap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ spec:
1616
labels:
1717
app.kubernetes.io/name: openldap
1818
spec:
19-
serviceAccountName: test-service-account
2019
containers:
2120
- name: openldap
2221
image: bitnamilegacy/openldap:2.5
@@ -54,6 +53,7 @@ spec:
5453
- ALL
5554
add:
5655
- NET_BIND_SERVICE
56+
serviceAccountName: test-service-account
5757
volumes:
5858
- name: tls
5959
csi:
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestAssert
4-
commands:
5-
- script: kubectl exec -n $NAMESPACE openldap-0 -- ldapsearch -H ldap://localhost:1389 -D cn=integrationtest,ou=users,dc=example,dc=org -w integrationtest -b ou=users,dc=example,dc=org > /dev/null
6-
- script: kubectl exec -n $NAMESPACE openldap-0 -- bash -c LDAPTLS_CACERT=/tls/ca.crt ldapsearch -Z -H ldaps://localhost:1636 -D cn=integrationtest,ou=users,dc=example,dc=org -w integrationtest -b ou=users,dc=example,dc=org > /dev/null
4+
timeout: 600
5+
---
6+
apiVersion: batch/v1
7+
kind: Job
8+
metadata:
9+
name: create-ldap-user
10+
status:
11+
succeeded: 1
Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,105 @@
11
---
2-
apiVersion: kuttl.dev/v1beta1
3-
kind: TestStep
2+
apiVersion: batch/v1
3+
kind: Job
44
metadata:
55
name: create-ldap-user
6-
commands:
7-
- script: kubectl cp -n $NAMESPACE ./create_ldap_user.sh openldap-0:/tmp
8-
- script: kubectl exec -n $NAMESPACE openldap-0 -- sh /tmp/create_ldap_user.sh
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: create-ldap-user
11+
image: bitnamilegacy/openldap:2.5
12+
command:
13+
- /bin/bash
14+
- -euxo
15+
- pipefail
16+
- -c
17+
args:
18+
- |
19+
ldapadd \
20+
-D cn=admin,dc=example,dc=org \
21+
-w admin \
22+
-f /stackable/ldap-users/integrationtest \
23+
|| true
24+
25+
ldappasswd \
26+
-D cn=admin,dc=example,dc=org \
27+
-w admin \
28+
-s integrationtest \
29+
cn=integrationtest,ou=users,dc=example,dc=org
30+
31+
# Check that the user works
32+
ldapsearch \
33+
-D cn=integrationtest,ou=users,dc=example,dc=org \
34+
-w integrationtest \
35+
-b ou=users,dc=example,dc=org
36+
env:
37+
- name: NAMESPACE
38+
valueFrom:
39+
fieldRef:
40+
fieldPath: metadata.namespace
41+
- name: LDAPURI
42+
value: ldaps://openldap.$(NAMESPACE).svc.cluster.local:1636/
43+
- name: LDAPTLS_CACERT
44+
value: /stackable/tls/ca.crt
45+
volumeMounts:
46+
- name: ldap-users
47+
mountPath: /stackable/ldap-users
48+
- name: tls
49+
mountPath: /stackable/tls
50+
securityContext:
51+
allowPrivilegeEscalation: false
52+
capabilities:
53+
drop:
54+
- ALL
55+
runAsNonRoot: true
56+
resources:
57+
requests:
58+
memory: 128Mi
59+
cpu: 100m
60+
limits:
61+
memory: 128Mi
62+
cpu: 400m
63+
volumes:
64+
- name: ldap-users
65+
configMap:
66+
name: ldap-users
67+
- name: tls
68+
ephemeral:
69+
volumeClaimTemplate:
70+
metadata:
71+
annotations:
72+
secrets.stackable.tech/class: tls
73+
spec:
74+
storageClassName: secrets.stackable.tech
75+
accessModes:
76+
- ReadWriteOnce
77+
resources:
78+
requests:
79+
storage: "1"
80+
serviceAccountName: test-service-account
81+
restartPolicy: OnFailure
82+
---
83+
apiVersion: v1
84+
kind: ConfigMap
85+
metadata:
86+
name: ldap-users
87+
data:
88+
integrationtest: |
89+
dn: cn=integrationtest,ou=users,dc=example,dc=org
90+
objectClass: inetOrgPerson
91+
objectClass: posixAccount
92+
objectClass: shadowAccount
93+
cn: integrationtest
94+
uid: integrationtest
95+
givenName: Stackable
96+
sn: Integration-Test
97+
mail: integrationtest@stackable.de
98+
uidNumber: 16842
99+
gidNumber: 100
100+
homeDirectory: /home/integrationtest
101+
loginShell: /bin/bash
102+
userPassword: {crypt}x
103+
shadowLastChange: 0
104+
shadowMax: 0
105+
shadowWarning: 0

tests/templates/kuttl/ldap/30-test-opensearch.yaml

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -68,99 +68,46 @@ metadata:
6868
name: test-opensearch
6969
data:
7070
test.py: |
71-
# https://docs.opensearch.org/docs/latest/clients/python-low-level/#sample-program
72-
7371
from opensearchpy import OpenSearch
7472
7573
host = 'opensearch'
7674
port = 9200
77-
auth = ('integrationtest', 'integrationtest') # For testing only. Don't store credentials in code.
75+
auth = ('integrationtest', 'integrationtest')
7876
ca_certs_path = '/stackable/tls/ca.crt'
7977
80-
# Create the client with SSL/TLS enabled, but hostname verification disabled.
8178
client = OpenSearch(
8279
hosts = [{'host': host, 'port': port}],
83-
http_compress = True, # enables gzip compression for request bodies
80+
http_compress = True,
8481
http_auth = auth,
85-
# client_cert = client_cert_path,
86-
# client_key = client_key_path,
8782
use_ssl = True,
8883
verify_certs = True,
8984
ssl_assert_hostname = False,
9085
ssl_show_warn = False,
9186
ca_certs = ca_certs_path
9287
)
9388
94-
# Create an index with non-default settings.
95-
index_name = 'python-test-index'
96-
index_body = {
97-
'settings': {
98-
'index': {
99-
'number_of_shards': 4
100-
}
101-
}
102-
}
89+
# Create an index
90+
index_name = 'test-index'
91+
92+
response = client.indices.create(index=index_name)
10393
104-
response = client.indices.create(index=index_name, body=index_body)
10594
print('\nCreating index:')
10695
print(response)
10796
108-
# Add a document to the index.
109-
document = {
110-
'title': 'Moneyball',
111-
'director': 'Bennett Miller',
112-
'year': '2011'
113-
}
114-
id = '1'
115-
97+
# Add a document to the index
11698
response = client.index(
117-
index = index_name,
118-
body = document,
119-
id = id,
120-
refresh = True
99+
index = index_name,
100+
body = {
101+
'name': 'Stackable'
102+
},
103+
id = 1,
121104
)
122105
123106
print('\nAdding document:')
124107
print(response)
125108
126-
# Perform bulk operations
127-
128-
movies = '{ "index" : { "_index" : "my-dsl-index", "_id" : "2" } } \n { "title" : "Interstellar", "director" : "Christopher Nolan", "year" : "2014"} \n { "create" : { "_index" : "my-dsl-index", "_id" : "3" } } \n { "title" : "Star Trek Beyond", "director" : "Justin Lin", "year" : "2015"} \n { "update" : {"_id" : "3", "_index" : "my-dsl-index" } } \n { "doc" : {"year" : "2016"} }'
129-
130-
client.bulk(body=movies)
131-
132-
# Search for the document.
133-
q = 'miller'
134-
query = {
135-
'size': 5,
136-
'query': {
137-
'multi_match': {
138-
'query': q,
139-
'fields': ['title^2', 'director']
140-
}
141-
}
142-
}
143-
144-
response = client.search(
145-
body = query,
146-
index = index_name
147-
)
148-
print('\nSearch results:')
149-
print(response)
150-
151-
# Delete the document.
152-
response = client.delete(
153-
index = index_name,
154-
id = id
155-
)
156-
157-
print('\nDeleting document:')
158-
print(response)
159-
160109
# Delete the index.
161-
response = client.indices.delete(
162-
index = index_name
163-
)
110+
response = client.indices.delete(index=index_name)
164111
165112
print('\nDeleting index:')
166113
print(response)

tests/templates/kuttl/ldap/create_ldap_user.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/templates/kuttl/smoke/20-test-opensearch.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ data:
8484
hosts = [{'host': host, 'port': port}],
8585
http_compress = True, # enables gzip compression for request bodies
8686
http_auth = auth,
87-
# client_cert = client_cert_path,
88-
# client_key = client_key_path,
8987
use_ssl = True,
9088
verify_certs = True,
9189
ssl_assert_hostname = False,

0 commit comments

Comments
 (0)