Skip to content

Commit

Permalink
Test with go test framework (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Makonike authored Jul 4, 2023
1 parent 78b4c31 commit 54d609c
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 284 deletions.
89 changes: 64 additions & 25 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ name: e2e
on: [pull_request, push]

jobs:
test-bind:
e2e-bind:
runs-on: ubuntu-latest

env:
GODEBUG: cgocheck=0
ENVOY_VERSION: v1.26.2
GO_VERSION: 1.19
steps:
- name: checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: ${{ env.GO_VERSION }}

- name: prepare glauth
run: |
Expand All @@ -25,26 +28,40 @@ jobs:
- name: run glauth
run: |
curl -L -o sample.cfg https://raw.githubusercontent.com/glauth/glauth/master/v2/sample-simple.cfg
sed -i "s#listen = \"0.0.0.0:3893\"#listen = \"$(ifconfig eth0 | grep 'inet ' | awk '{print $2}'):3893\"#" sample.cfg
./glauth -c sample.cfg &
sleep 5
- name: test-bind-mode
- name: build
run: |
sed -i "s/host: localhost/host: $(ifconfig eth0 | awk '/inet / {print $2}')/" example/envoy.yaml
make test-bind-mode
make build
sudo mkdir -p /etc/envoy
sudo cp libgolang.so /etc/envoy/libgolang.so
test-search:
runs-on: ubuntu-latest
- name: envoy
run: |
curl -L -o envoy https://github.com/envoyproxy/envoy/releases/download/${ENVOY_VERSION}/envoy-contrib-x86_64
chmod +x envoy
sudo cp envoy /usr/bin/envoy
sudo chmod +x /usr/bin/envoy
- name: test
run: |
go test test/e2e_bind_test.go test/common.go
e2e-search:
runs-on: ubuntu-latest
env:
GODEBUG: cgocheck=0
ENVOY_VERSION: v1.26.2
GO_VERSION: 1.19
steps:
- name: checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: ${{ env.GO_VERSION }}

- name: prepare glauth
run: |
Expand All @@ -57,26 +74,40 @@ jobs:
- name: run glauth
run: |
curl -L -o sample.cfg https://raw.githubusercontent.com/glauth/glauth/master/v2/sample-simple.cfg
sed -i "s#listen = \"0.0.0.0:3893\"#listen = \"$(ifconfig eth0 | grep 'inet ' | awk '{print $2}'):3893\"#" sample.cfg
./glauth -c sample.cfg &
sleep 5
- name: test-search-mode
- name: build
run: |
sed -i "s/host: localhost/host: $(ifconfig eth0 | awk '/inet / {print $2}')/" example/envoy-search.yaml
make test-search-mode
make build
sudo mkdir -p /etc/envoy
sudo cp libgolang.so /etc/envoy/libgolang.so
test-tls:
runs-on: ubuntu-latest
- name: envoy
run: |
curl -L -o envoy https://github.com/envoyproxy/envoy/releases/download/${ENVOY_VERSION}/envoy-contrib-x86_64
chmod +x envoy
sudo cp envoy /usr/bin/envoy
sudo chmod +x /usr/bin/envoy
- name: test
run: |
go test test/e2e_search_test.go test/common.go
e2e-tls:
runs-on: ubuntu-latest
env:
GODEBUG: cgocheck=0
ENVOY_VERSION: v1.26.2
GO_VERSION: 1.19
steps:
- name: checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: ${{ env.GO_VERSION }}

- name: prepare glauth
run: |
Expand All @@ -90,18 +121,26 @@ jobs:
openssl genpkey -algorithm RSA -out glauth.key -pkeyopt rsa_keygen_bits:2048
openssl req -new -key glauth.key -out glauth.csr -config example/tls/csr.conf
openssl x509 -req -in glauth.csr -signkey glauth.key -out glauth.crt -extensions req_ext -extfile example/tls/csr.conf -days 365
- name: build
run: make build
cp glauth.crt test/glauth.crt
- name: run glauth
run: |
./glauth -c sample.cfg &
sleep 5
- name: test-tls
- name: build
run: |
sed -i "s/host: localhost/host: $(ifconfig eth0 | awk '/inet / {print $2}')/" example/envoy-tls.yaml
awk 'FNR==NR{a=a$0"\\n";next} /rootCA: # ""/{sub(/rootCA: # ""/, "rootCA: \""a"\"")} 1' glauth.crt example/envoy-tls.yaml > example/envoy.yaml.tmp && mv example/envoy.yaml.tmp example/envoy-tls.yaml
make test-tls
make build
sudo mkdir -p /etc/envoy
sudo cp libgolang.so /etc/envoy/libgolang.so
- name: envoy
run: |
curl -L -o envoy https://github.com/envoyproxy/envoy/releases/download/${ENVOY_VERSION}/envoy-contrib-x86_64
chmod +x envoy
sudo cp envoy /usr/bin/envoy
sudo chmod +x /usr/bin/envoy
- name: test
run: |
go test test/e2e_tls_test.go test/common.go
44 changes: 1 addition & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build run test-bind-mode test-search-mode test-tls clean
.PHONY: build run clean

build:
docker run --rm -v $(PWD):/go/src/go-filter -w /go/src/go-filter \
Expand All @@ -16,47 +16,5 @@ run:
envoyproxy/envoy:contrib-v1.26.1 \
envoy -c /etc/envoy/envoy.yaml

test-bind-mode:
docker rm -f envoy-ldap-test
docker run --rm -v $(PWD)/example/envoy.yaml:/etc/envoy/envoy.yaml \
-v $(PWD)/libgolang.so:/etc/envoy/libgolang.so \
-e "GODEBUG=cgocheck=0" \
-p 10000:10000 \
--name envoy-ldap-test \
envoyproxy/envoy:contrib-v1.26.1 \
envoy -c /etc/envoy/envoy.yaml &
sleep 5
go test test/e2e_bind_test.go

docker rm -f envoy-ldap-test

test-search-mode:
docker rm -f envoy-ldap-test
docker run --rm -v $(PWD)/example/envoy-search.yaml:/etc/envoy/envoy.yaml \
-v $(PWD)/libgolang.so:/etc/envoy/libgolang.so \
-e "GODEBUG=cgocheck=0" \
-p 10000:10000 \
--name envoy-ldap-test \
envoyproxy/envoy:contrib-v1.26.1 \
envoy -c /etc/envoy/envoy.yaml &
sleep 5
go test test/e2e_search_test.go

docker rm -f envoy-ldap-test

test-tls:
docker rm -f envoy-ldap-test
docker run --rm -v $(PWD)/example/envoy-tls.yaml:/etc/envoy/envoy.yaml \
-v $(PWD)/libgolang.so:/etc/envoy/libgolang.so \
-e "GODEBUG=cgocheck=0" \
-p 10000:10000 \
--name envoy-ldap-test \
envoyproxy/envoy:contrib-v1.26.1 \
envoy -c /etc/envoy/envoy.yaml &
sleep 5
go test test/e2e_bind_test.go

docker rm -f envoy-ldap-test

clean:
docker rm -f envoy-ldap-test
53 changes: 4 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ http_filters:
value:
# required
host: localhost
port: 389
baseDn: dc=example,dc=com
port: 3894
baseDn: dc=glauth,dc=com
attribute: cn
# optional
# be used in search mode
Expand Down Expand Up @@ -72,10 +72,6 @@ chmod +x glauth

# download sample config file of glauth
curl -L -o sample.cfg https://raw.githubusercontent.com/glauth/glauth/master/v2/sample-simple.cfg

# modify sample.cfg, replace listen address with your ip address.
# In Linux, you can execute it as follows:
sed -i "s#listen = \"0.0.0.0:3893\"#listen = \"$(ifconfig en0 | grep 'inet ' | awk '{print $2}'):3893\"#" sample.cfg
```

Then, start glauth.
Expand All @@ -84,51 +80,10 @@ Then, start glauth.
./glauth -c sample.cfg
```

Modify your envoy.yaml, and you can find this example file in `example` directory.

```yaml
http_filters:
- name: envoy.filters.http.golang
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.golang.v3alpha.Config
library_id: example
library_path: /etc/envoy/libgolang.so
plugin_name: envoy-go-ldap-auth
plugin_config:
"@type": type.googleapis.com/xds.type.v3.TypedStruct
value:
# required
host: localhost
port: 3893
baseDn: dc=glauth,dc=com
attribute: cn
# optional
# be used in search mode
bindDn: # cn=admin,dc=example,dc=com
bindPassword: # mypassword
# if the filter is set, the filter application will run in search mode.
filter: # (&(objectClass=inetOrgPerson)(gidNumber=500)(uid=%s))
timeout: 60 # unit is second.
tls: # false
startTLS: # false
insecureSkipVerify: # false
rootCA: # "
```
Replace the host of the LDAP server with your ip address.
```bash
sed -i "s/host: localhost/host: $(ifconfig en0 | awk '/inet / {print $2}')/" example/envoy.yaml
```
Start and test filter.
```bash
make build
make run
```
Run it with the example config file.

```bash
go test test/e2e_bind_test.go
go test test/e2e_bind_test.go test/common.go
```

## Bind Mode and Search Mode
Expand Down
79 changes: 0 additions & 79 deletions example/envoy-search.yaml

This file was deleted.

Loading

0 comments on commit 54d609c

Please sign in to comment.