-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (77 loc) · 2.7 KB
/
Makefile
File metadata and controls
92 lines (77 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
.PHONY: default install build test test fmt vet lint
default: fmt vet lint build test
CONTAINER_CMD := $(shell (command -v docker 2>/dev/null || command -v podman 2>/dev/null))
ifeq ($(CONTAINER_CMD),)
$(error Neither podman nor docker found in PATH)
endif
install:
go get -t -x ./...
build:
go build -v ./...
LDAP_ADMIN_DN := cn=admin,dc=example,dc=com
LDAP_ADMIN_PASSWORD := admin123
LDAP_BASE_DN := dc=example,dc=com
LDAP_URL := ldap://127.0.0.1:389
CONTAINER_NAME := go-ldap-test
local-server:
-$(CONTAINER_CMD) rm -f $(CONTAINER_NAME)
$(CONTAINER_CMD) \
run \
--rm \
-d \
--name $(CONTAINER_NAME) \
--hostname "$(CONTAINER_NAME).example.com" \
-p "127.0.0.1:3389:389" \
-p "127.0.0.1:3636:636" \
-e LDAP_ORGANISATION="Example Inc" \
-e LDAP_DOMAIN="example.com" \
-e LDAP_ADMIN_PASSWORD="$(LDAP_ADMIN_PASSWORD)" \
-e LDAP_TLS_VERIFY_CLIENT="never" \
docker.io/osixia/openldap:1.5.0
@echo "Waiting for LDAP server to be ready..."
@$(CONTAINER_CMD) exec $(CONTAINER_NAME) /bin/sh -c 'until ldapsearch -x -H $(LDAP_URL) -b "$(LDAP_BASE_DN)" -D "$(LDAP_ADMIN_DN)" -w $(LDAP_ADMIN_PASSWORD) > /dev/null 2>&1; do echo "LDAP server not ready yet, waiting..."; sleep 2; done'
@echo "LDAP server is ready!"
@echo "Configuring anonymous access..."
@$(CONTAINER_CMD) exec $(CONTAINER_NAME) /bin/sh -c 'echo "dn: olcDatabase={1}mdb,cn=config\nchangetype: modify\nreplace: olcAccess\nolcAccess: {0}to * by * read" | ldapmodify -Y EXTERNAL -H ldapi:///'
$(CONTAINER_CMD) cp -a ./testdata $(CONTAINER_NAME):/
@echo "Loading LDIF files..."
@$(CONTAINER_CMD) exec $(CONTAINER_NAME) /bin/sh -c 'for file in /testdata/*.ldif; do echo "Processing $$file..."; cat "$$file" | ldapadd -v -x -H $(LDAP_URL) -D "$(LDAP_ADMIN_DN)" -w $(LDAP_ADMIN_PASSWORD); done'
stop-local-server:
-$(CONTAINER_CMD) rm -f -t 10 $(CONTAINER_NAME)
test:
go test -v -cover -race -count=1 .
fuzz:
(cd v3 && go test -fuzz=FuzzGetLDAPError -fuzztime=600s .)
# Capture output and force failure when there is non-empty output
fmt:
@echo gofmt -l .
@OUTPUT=`gofmt -l . 2>&1`; \
if [ "$$OUTPUT" ]; then \
echo "gofmt must be run on the following files:"; \
echo "$$OUTPUT"; \
exit 1; \
fi
vet:
go vet \
-atomic \
-bool \
-copylocks \
-nilfunc \
-printf \
-rangeloops \
-unreachable \
-unsafeptr \
-unusedresult \
./...
# https://github.com/golang/lint
# go get github.com/golang/lint/golint
# Capture output and force failure when there is non-empty output
# Only run on go1.5+
lint:
@echo golint ./...
@OUTPUT=`command -v golint >/dev/null 2>&1 && golint ./... 2>&1`; \
if [ "$$OUTPUT" ]; then \
echo "golint errors:"; \
echo "$$OUTPUT"; \
exit 1; \
fi