Skip to content

Commit 5d08771

Browse files
authored
feat: add unknown operation for test (#9)
1 parent 3734b38 commit 5d08771

File tree

4 files changed

+137
-1
lines changed

4 files changed

+137
-1
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
4444
- name: script
4545
run: |
46-
sudo docker run --detach --rm --name openldap -p 1389:1389 -p 1636:1636 -v $PWD/t/certs:/opt/bitnami/openldap/certs -e LDAP_ENABLE_TLS=yes -e LDAP_TLS_CERT_FILE=/opt/bitnami/openldap/certs/localhost_slapd_cert.pem -e LDAP_TLS_KEY_FILE=/opt/bitnami/openldap/certs/localhost_slapd_key.pem -e LDAP_TLS_CA_FILE=/opt/bitnami/openldap/certs/mycacert.crt -e LDAP_USERS=user01,user02 -e LDAP_PASSWORDS=password1,password2 bitnami/openldap:2.6
46+
sudo docker run --detach --rm --name openldap -p 1389:1389 -p 1636:1636 -v $PWD/t/certs:/opt/bitnami/openldap/certs -e LDAP_ENABLE_TLS=yes -e LDAP_TLS_CERT_FILE=/opt/bitnami/openldap/certs/localhost_slapd_cert.pem -e LDAP_TLS_KEY_FILE=/opt/bitnami/openldap/certs/localhost_slapd_key.pem -e LDAP_TLS_CA_FILE=/opt/bitnami/openldap/certs/mycacert.crt -e LDAP_ADMIN_USERNAME=admin -e LDAP_ADMIN_PASSWORD=adminpassword -e LDAP_USERS=user01,user02 -e LDAP_PASSWORDS=password1,password2 bitnami/openldap:2.6
4747
sleep 3
4848
export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$PATH
4949
make test

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ help:
2121
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'
2222

2323
test:
24+
git apply t/patch/unknown_op.patch
2425
prove -r t/
26+
git apply t/patch/unknown_op.patch -R

t/patch/unknown_op.patch

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/lib/resty/ldap/client.lua b/lib/resty/ldap/client.lua
2+
index 6b8eb18..45cef3f 100644
3+
--- a/lib/resty/ldap/client.lua
4+
+++ b/lib/resty/ldap/client.lua
5+
@@ -257,4 +257,14 @@ function _M.search(self, base_dn, scope, deref_aliases, size_limit, time_limit,
6+
end
7+
8+
9+
+function _M.unknown(self, hex_data, multi_resp_hint)
10+
+ local raw_data = hex_data:gsub("%x%x", function(digits) return string.char(tonumber(digits, 16)) end)
11+
+ local res, err = _send_recieve(self, raw_data, multi_resp_hint or false)
12+
+ if not res then
13+
+ return false, err
14+
+ end
15+
+ return res
16+
+end
17+
+
18+
+
19+
return _M

t/search.t

+115
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,118 @@ GET /t
571571
--- no_error_log
572572
[error]
573573
--- error_code: 200
574+
575+
576+
577+
=== TEST 17: add new Chinese attribute to user01
578+
--- http_config eval: $::HttpConfig
579+
--- config
580+
location /t {
581+
content_by_lua_block {
582+
local ldap_client = require("resty.ldap.client")
583+
local ldap_protocol = require("resty.ldap.protocol")
584+
585+
local client = ldap_client:new("127.0.0.1", 1389)
586+
587+
-- auth
588+
local res, err = client:simple_bind("cn=admin,dc=example,dc=org", "adminpassword")
589+
if not res then
590+
ngx.log(ngx.ERR, err)
591+
ngx.exit(401)
592+
end
593+
594+
assert(res, "failed to bind admin")
595+
596+
-- modify
597+
local res, err = client:unknown(
598+
"304b02012266460424636e3d7573657230312c6f753d75736572732c64633d6578616d706c652c64633d6f7267301e301c0a01003017040b646973706c61794e616d6531080406e4b8ade69687", -- hex
599+
false
600+
)
601+
if not res then
602+
ngx.log(ngx.ERR, err)
603+
ngx.exit(401)
604+
end
605+
606+
assert(res.protocol_op == 7, "protocol_op is not equal to 7, " .. res.protocol_op)
607+
assert(res.result_code == 0, "result_code is not equal to 0, " .. res.result_code)
608+
}
609+
}
610+
--- request
611+
GET /t
612+
--- no_error_log
613+
[error]
614+
--- error_code: 200
615+
616+
617+
618+
=== TEST 18: search filter (attribute value in Chinese)
619+
--- http_config eval: $::HttpConfig
620+
--- config
621+
location /t {
622+
content_by_lua_block {
623+
local ldap_client = require("resty.ldap.client")
624+
local ldap_protocol = require("resty.ldap.protocol")
625+
626+
local client = ldap_client:new("127.0.0.1", 1389)
627+
local res, err = client:search(
628+
"dc=example,dc=org",
629+
ldap_protocol.SEARCH_SCOPE_WHOLE_SUBTREE, nil, nil, nil, nil,
630+
"(displayName=中文)", {"gidNumber"}
631+
)
632+
633+
if not res then
634+
ngx.log(ngx.ERR, err)
635+
ngx.exit(401)
636+
end
637+
638+
assert(#res == 1, "result length is not equal to 1")
639+
assert(res[1].entryDN == "cn=user01,ou=users,dc=example,dc=org", "result entryDN is not equal to cn=user01,ou=users,dc=example,dc=org")
640+
assert(res[1].attributes.gidNumber == "1000", "result gidNumber attribute is not equal to 1000")
641+
}
642+
}
643+
--- request
644+
GET /t
645+
--- no_error_log
646+
[error]
647+
--- error_code: 200
648+
649+
650+
651+
=== TEST 19: remove Chinese attribute in user01
652+
--- http_config eval: $::HttpConfig
653+
--- config
654+
location /t {
655+
content_by_lua_block {
656+
local ldap_client = require("resty.ldap.client")
657+
local ldap_protocol = require("resty.ldap.protocol")
658+
659+
local client = ldap_client:new("127.0.0.1", 1389)
660+
661+
-- auth
662+
local res, err = client:simple_bind("cn=admin,dc=example,dc=org", "adminpassword")
663+
if not res then
664+
ngx.log(ngx.ERR, err)
665+
ngx.exit(401)
666+
end
667+
668+
assert(res, "failed to bind admin")
669+
670+
-- modify
671+
local res, err = client:unknown(
672+
"304b02014066460424636e3d7573657230312c6f753d75736572732c64633d6578616d706c652c64633d6f7267301e301c0a01013017040b646973706c61794e616d6531080406e4b8ade69687", -- hex
673+
false
674+
)
675+
if not res then
676+
ngx.log(ngx.ERR, err)
677+
ngx.exit(401)
678+
end
679+
680+
assert(res.protocol_op == 7, "protocol_op is not equal to 7, " .. res.protocol_op)
681+
assert(res.result_code == 0, "result_code is not equal to 0, " .. res.result_code)
682+
}
683+
}
684+
--- request
685+
GET /t
686+
--- no_error_log
687+
[error]
688+
--- error_code: 200

0 commit comments

Comments
 (0)