Skip to content

Commit 7e1bfee

Browse files
committed
Initial commit
0 parents  commit 7e1bfee

File tree

11 files changed

+957
-0
lines changed

11 files changed

+957
-0
lines changed

.github/workflows/lint.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- master
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
12+
# pull-requests: read
13+
14+
jobs:
15+
golangci:
16+
name: lint
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-go@v5
22+
with:
23+
go-version: 1.23.x
24+
check-latest: true
25+
26+
- name: golangci-lint
27+
uses: golangci/golangci-lint-action@v6
28+
with:
29+
version: v1.60

.github/workflows/test.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Tests
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
6+
defaults:
7+
run:
8+
shell: bash
9+
10+
jobs:
11+
webcrypto:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version: 1.23.x
19+
check-latest: true
20+
21+
- name: Start LDAP container for tests
22+
uses: hoverkraft-tech/[email protected]
23+
with:
24+
compose-file: "./test/docker-compose.yml"
25+
26+
- name: Run tests
27+
run: |
28+
set -x
29+
go test ./...

.golangci.yml

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# v1.60.1
2+
# Please don't remove the first line. It uses in CI to determine the golangci version
3+
run:
4+
timeout: 5m
5+
6+
issues:
7+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
8+
max-issues-per-linter: 0
9+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
10+
max-same-issues: 0
11+
12+
# We want to try and improve the comments in the k6 codebase, so individual
13+
# non-golint items from the default exclusion list will gradually be added
14+
# to the exclude-rules below
15+
exclude-use-default: false
16+
17+
exclude-rules:
18+
# Exclude duplicate code and function length and complexity checking in test
19+
# files (due to common repeats and long functions in test code)
20+
- path: _(test|gen)\.go
21+
linters:
22+
- canonicalheader
23+
- cyclop
24+
- dupl
25+
- gocognit
26+
- funlen
27+
- lll
28+
- forcetypeassert
29+
- path: js\/modules\/k6\/html\/.*\.go
30+
text: "exported: exported "
31+
linters:
32+
- revive
33+
- path: js\/modules\/k6\/http\/.*_test\.go
34+
linters:
35+
# k6/http module's tests are quite complex because they often have several nested levels.
36+
# The module is in maintenance mode, so we don't intend to port the tests to a parallel version.
37+
- paralleltest
38+
- tparallel
39+
- linters:
40+
- forbidigo
41+
text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden'
42+
43+
linters-settings:
44+
exhaustive:
45+
default-signifies-exhaustive: true
46+
cyclop:
47+
max-complexity: 25
48+
dupl:
49+
threshold: 150
50+
goconst:
51+
min-len: 10
52+
min-occurrences: 4
53+
funlen:
54+
lines: 80
55+
statements: 60
56+
forbidigo:
57+
forbid:
58+
- '^(fmt\\.Print(|f|ln)|print|println)$'
59+
# Forbid everything in os, except os.Signal and os.SyscalError
60+
- '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?'
61+
# Forbid everything in syscall except the uppercase constants
62+
- '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?'
63+
- '^logrus\.Logger$'
64+
65+
linters:
66+
disable-all: true
67+
enable:
68+
- asasalint
69+
- asciicheck
70+
- bidichk
71+
- bodyclose
72+
- canonicalheader
73+
- contextcheck
74+
- cyclop
75+
- dogsled
76+
- dupl
77+
- durationcheck
78+
- errcheck
79+
- errchkjson
80+
- errname
81+
- errorlint
82+
- exhaustive
83+
- exportloopref
84+
- fatcontext
85+
- forbidigo
86+
- forcetypeassert
87+
- funlen
88+
- gocheckcompilerdirectives
89+
- gochecknoglobals
90+
- gocognit
91+
- goconst
92+
- gocritic
93+
- gofmt
94+
- gofumpt
95+
- goimports
96+
- gomoddirectives
97+
- goprintffuncname
98+
- gosec
99+
- gosimple
100+
- govet
101+
- importas
102+
- ineffassign
103+
- interfacebloat
104+
- lll
105+
- makezero
106+
- misspell
107+
- nakedret
108+
- nestif
109+
- nilerr
110+
- nilnil
111+
- noctx
112+
- nolintlint
113+
- nosprintfhostport
114+
- paralleltest
115+
- prealloc
116+
- predeclared
117+
- promlinter
118+
- revive
119+
- reassign
120+
- rowserrcheck
121+
- sqlclosecheck
122+
- staticcheck
123+
- stylecheck
124+
- tenv
125+
- tparallel
126+
- typecheck
127+
- unconvert
128+
- unparam
129+
- unused
130+
- usestdlibvars
131+
- wastedassign
132+
- whitespace
133+
fast: false

Makefile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
MAKEFLAGS += --silent
2+
GOLANGCI_CONFIG ?= .golangci.yml
3+
4+
all: clean lint test build
5+
6+
## help: Prints a list of available build targets.
7+
help:
8+
echo "Usage: make <OPTIONS> ... <TARGETS>"
9+
echo ""
10+
echo "Available targets are:"
11+
echo ''
12+
sed -n 's/^##//p' ${PWD}/Makefile | column -t -s ':' | sed -e 's/^/ /'
13+
echo
14+
echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`"
15+
16+
## build: Builds a custom 'k6' with the local extension.
17+
build:
18+
xk6 build --with $(shell go list -m)=.
19+
20+
## linter-config: Checks if the linter config exists, if not, downloads it from the main k6 repository.
21+
linter-config:
22+
test -s "${GOLANGCI_CONFIG}" || (echo "No linter config, downloading from main k6 repository..." && curl --silent --show-error --fail --no-location https://raw.githubusercontent.com/grafana/k6/master/.golangci.yml --output "${GOLANGCI_CONFIG}")
23+
24+
## check-linter-version: Checks if the linter version is the same as the one specified in the linter config.
25+
check-linter-version:
26+
(golangci-lint version | grep "version $(shell head -n 1 .golangci.yml | tr -d '\# ')") || echo "Your installation of golangci-lint is different from the one that is specified in k6's linter config (there it's $(shell head -n 1 .golangci.yml | tr -d '\# ')). Results could be different in the CI."
27+
28+
## test: Executes any tests.
29+
test:
30+
go test -race -timeout 60s ./...
31+
32+
## lint: Runs the linters.
33+
lint: linter-config check-linter-version
34+
echo "Running linters..."
35+
golangci-lint run --out-format=tab ./...
36+
37+
## check: Runs the linters and tests.
38+
check: lint test
39+
40+
## clean: Removes any previously created artifacts/downloads.
41+
clean:
42+
echo "Cleaning up..."
43+
rm -f ./k6
44+
rm -f .golangci.yml
45+
46+
.PHONY: test lint check build clean linter-config check-linter-version

examples/example.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import ldap from 'k6/x/ldap'
2+
3+
4+
// Open the connection in the init section, called once per run
5+
// It's a good idea not to open a connection per VU unless you specifically want to test that
6+
const ldapUrl = 'ldap://localhost:1389'
7+
console.log(`Dialing LDAP URL: ${ldapUrl}`)
8+
let ldapConn = ldap.dialUrl(ldapUrl)
9+
10+
let bindDn = 'cn=admin,dc=example,dc=org'
11+
let bindPassword = 'adminpassword'
12+
console.log(`Binding to LDAP with DN: ${bindDn}`)
13+
ldapConn.bind(bindDn, bindPassword)
14+
15+
export default function () {
16+
let filter = '(cn=*)'
17+
let baseDn = 'dc=example,dc=org'
18+
let attributes = ['cn', 'sn', 'objectClass'] // [] for all attributes
19+
let scope = 'WholeSubtree' // options: BaseObject, SingleLevel, WholeSubtree
20+
let sizeLimit = 0 // 0 for unlimited
21+
let timeLimit = 0 // (seconds). 0 for unlimited
22+
23+
let searchReq = ldap.newSearchRequest(baseDn, scope, sizeLimit, timeLimit, filter, attributes)
24+
25+
let result = ldapConn.search(searchReq)
26+
console.log(`Search found ${result.entries.length} results`)
27+
28+
let addRequest = ldap.newAddRequest('cn=test,dc=example,dc=org')
29+
addRequest.attribute('sn', ['Smith'])
30+
addRequest.attribute('objectClass', ['inetOrgPerson'])
31+
console.log('Running Add request')
32+
ldapConn.add(addRequest)
33+
34+
35+
result = ldapConn.search(searchReq)
36+
console.log(`Search found ${result.entries.length} results`)
37+
38+
let delRequest = ldap.newDelRequest('cn=test,dc=example,dc=org')
39+
console.log('Running Delete request')
40+
ldapConn.del(addRequest)
41+
42+
}
43+
44+
export function teardown() {
45+
ldapConn.close()
46+
console.log('LDAP connection closed')
47+
}

go.mod

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
module xk6-ldap
2+
3+
go 1.22.1
4+
5+
require (
6+
github.com/stretchr/testify v1.9.0
7+
go.k6.io/k6 v0.55.0
8+
gopkg.in/ldap.v3 v3.0.3
9+
)
10+
11+
require (
12+
buf.build/gen/go/gogo/protobuf/protocolbuffers/go v1.31.0-20210810001428-4df00b267f94.1 // indirect
13+
buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.31.0-20230627135113-9a12bc2590d2.1 // indirect
14+
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
15+
github.com/PuerkitoBio/goquery v1.9.2 // indirect
16+
github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 // indirect
17+
github.com/andybalholm/brotli v1.1.1 // indirect
18+
github.com/andybalholm/cascadia v1.3.2 // indirect
19+
github.com/beorn7/perks v1.0.1 // indirect
20+
github.com/bufbuild/protocompile v0.14.1 // indirect
21+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
22+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
23+
github.com/chromedp/cdproto v0.0.0-20240919203636-12af5e8a671f // indirect
24+
github.com/chromedp/sysutil v1.0.0 // indirect
25+
github.com/davecgh/go-spew v1.1.1 // indirect
26+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
27+
github.com/dlclark/regexp2 v1.11.4 // indirect
28+
github.com/evanw/esbuild v0.21.2 // indirect
29+
github.com/fatih/color v1.18.0 // indirect
30+
github.com/go-logr/logr v1.4.2 // indirect
31+
github.com/go-logr/stdr v1.2.2 // indirect
32+
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
33+
github.com/golang/protobuf v1.5.4 // indirect
34+
github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect
35+
github.com/google/uuid v1.6.0 // indirect
36+
github.com/gorilla/websocket v1.5.3 // indirect
37+
github.com/grafana/sobek v0.0.0-20241024150027-d91f02b05e9b // indirect
38+
github.com/grafana/xk6-browser v1.9.1 // indirect
39+
github.com/grafana/xk6-dashboard v0.7.5 // indirect
40+
github.com/grafana/xk6-output-opentelemetry v0.3.0 // indirect
41+
github.com/grafana/xk6-output-prometheus-remote v0.5.0 // indirect
42+
github.com/grafana/xk6-redis v0.3.1 // indirect
43+
github.com/grafana/xk6-webcrypto v0.5.0 // indirect
44+
github.com/grafana/xk6-websockets v0.7.2 // indirect
45+
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
46+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
47+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
48+
github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc // indirect
49+
github.com/jhump/protoreflect v1.17.0 // indirect
50+
github.com/josharian/intern v1.0.0 // indirect
51+
github.com/klauspost/compress v1.17.11 // indirect
52+
github.com/mailru/easyjson v0.7.7 // indirect
53+
github.com/mattn/go-colorable v0.1.13 // indirect
54+
github.com/mattn/go-isatty v0.0.20 // indirect
55+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
56+
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
57+
github.com/mstoykov/envconfig v1.5.0 // indirect
58+
github.com/mstoykov/k6-taskqueue-lib v0.1.0 // indirect
59+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
60+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
61+
github.com/pmezard/go-difflib v1.0.0 // indirect
62+
github.com/prometheus/client_golang v1.16.0 // indirect
63+
github.com/prometheus/client_model v0.4.0 // indirect
64+
github.com/prometheus/common v0.42.0 // indirect
65+
github.com/prometheus/procfs v0.10.1 // indirect
66+
github.com/r3labs/sse/v2 v2.10.0 // indirect
67+
github.com/redis/go-redis/v9 v9.0.5 // indirect
68+
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
69+
github.com/sirupsen/logrus v1.9.3 // indirect
70+
github.com/spf13/afero v1.1.2 // indirect
71+
github.com/spf13/cobra v1.4.0 // indirect
72+
github.com/spf13/pflag v1.0.5 // indirect
73+
github.com/tidwall/gjson v1.18.0 // indirect
74+
github.com/tidwall/match v1.1.1 // indirect
75+
github.com/tidwall/pretty v1.2.1 // indirect
76+
go.opentelemetry.io/otel v1.29.0 // indirect
77+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 // indirect
78+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0 // indirect
79+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
80+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0 // indirect
81+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect
82+
go.opentelemetry.io/otel/metric v1.29.0 // indirect
83+
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
84+
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
85+
go.opentelemetry.io/otel/trace v1.29.0 // indirect
86+
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
87+
go.uber.org/goleak v1.3.0 // indirect
88+
golang.org/x/crypto v0.28.0 // indirect
89+
golang.org/x/crypto/x509roots/fallback v0.0.0-20240806160748-b2d3a6a4b4d3 // indirect
90+
golang.org/x/net v0.30.0 // indirect
91+
golang.org/x/sync v0.8.0 // indirect
92+
golang.org/x/sys v0.26.0 // indirect
93+
golang.org/x/term v0.25.0 // indirect
94+
golang.org/x/text v0.19.0 // indirect
95+
golang.org/x/time v0.7.0 // indirect
96+
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
97+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
98+
google.golang.org/grpc v1.67.1 // indirect
99+
google.golang.org/protobuf v1.35.1 // indirect
100+
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
101+
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
102+
gopkg.in/guregu/null.v3 v3.3.0 // indirect
103+
gopkg.in/yaml.v3 v3.0.1 // indirect
104+
)

0 commit comments

Comments
 (0)