Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the latest extensions standard #8

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
.DS_Store
k6
75 changes: 75 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting our Developer Relations team, avocados@k6.io.

All complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
MAKEFLAGS += --silent

all: clean format test build

## help: Prints a list of available build targets.
help:
echo "Usage: make <OPTIONS> ... <TARGETS>"
echo ""
echo "Available targets are:"
echo ''
sed -n 's/^##//p' ${PWD}/Makefile | column -t -s ':' | sed -e 's/^/ /'
echo
echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`"

## clean: Removes any previously created build artifacts.
clean:
rm -f ./k6

## build: Builds a custom 'k6' with the local extension.
build:
go install go.k6.io/xk6/cmd/xk6@latest
xk6 build --with $(shell go list -m)=.

## format: Applies Go formatting to code.
format:
go fmt ./...

## test: Executes any unit tests.
test:
go test -cover -race ./...

.PHONY: build clean format help test
54 changes: 34 additions & 20 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
> ### ⚠️ This is a proof of concept
>
> As this is a proof of concept, it won't be supported by the k6 team.
> It may also break in the future as xk6 evolves. USE AT YOUR OWN RISK!
> Any issues with the tool should be raised [here](https://github.com/k6io/xk6-ssh/issues).

</br>
</br>

<div align="center">

# xk6-ssh
A k6 extension for using of SSH in testing. Built for [k6](https://go.k6.io/k6) using [xk6](https://github.com/k6io/xk6).

</div>
A k6 extension for using of SSH in testing. Built for [k6](https://github.com/grafana/k6) using [xk6](https://github.com/grafana/xk6).

## Build

Expand All @@ -25,24 +12,27 @@ Then:

1. Download `xk6`:
```bash
$ go install github.com/k6io/xk6/cmd/xk6@latest
go install github.com/grafana/xk6/cmd/xk6@latest
```

2. Build the binary:
```bash
$ xk6 build --with github.com/k6io/xk6-ssh@latest
xk6 build --with github.com/grafana/xk6-ssh@latest
```

This will result in a `k6` binary in the current directory.

## Example

```javascript
import ssh from 'k6/x/ssh';

export default function () {
ssh.connect({
username: 'USERNAME',
host: "HOST_ADDRESS",
port: 22
username: `${__ENV.K6_USERNAME}`,
password: `${__ENV.K6_PASSWORD}`,
host: [HOSTNAME],
port: 22
})
console.log(ssh.run('pwd'))
}
Expand Down Expand Up @@ -80,8 +70,32 @@ default ✓ [======================================] 1 VUs 00m01.4s/10m0s 1/1

```

Inspect examples folder for more details.
## Testing Locally
This repo includes a [docker-compose.yml](docker-compose.yml) file that starts an [OpenSSH Server](https://docs.linuxserver.io/images/docker-openssh-server) from [LinuxServer.io](https://www.linuxserver.io/).
The `examples` directory contains scripts that are configured to work with this environment out of the box.

> :warning: Be sure that you've already compiled your custom `k6` binary as described in the [Build](#build) section!

We'll use this environment to run some examples.

1. Start the docker compose environment.

```shell
docker compose up -d
```
Once you see the following, you should be ready.
```shell
[+] Running 2/2
⠿ Network xk6-ssh_default Created
⠿ Container xk6-ssh-openssh-server-1 Started
```
Next, we'll use the `k6` binary we compiled in the [Build section](#build) above.

1. Using our custom `k6` binary, we can execute our [example scripts](examples/).
```shell
./k6 run examples/connect-by-rsa-key.js
```
The RSA example will then connect to the local SSH server using the `example_rsa` private key.

## FAQ

Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.9'

services:
openssh-server:
image: linuxserver/openssh-server:latest
environment:
- PUBLIC_KEY=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFj+MNxxbNXjHBM6M8btIkeAoeLkGt5fkmlAW7lYDcRIQj06FX0SGWK+yL2kHY6sxJJbmxchSmb4J/BJkHY22+OuWjxfO/YIEL3faWmwbISgPnky7R77IW7M95OBzOQvWXv2AXUlXatqg6GDmeCQlqLHzfKgwUHosP61tGMnFf8NFOtBNIgKpopODSqD3eq79bv//9NHu0xbajheL01Yg3XbvFYKlo0thvYITqvC+kX++K9PyrwSK/LPGIW0xqXvFEwlDqOcSrIbfkzRPkco6/3ANfPrYDlnT1MpTcPJGH31wk85AUPE6axK0CL4vsEICrhmXJff2hqRKHvAjMhU+deHlb3DCMwJ8dkFpuRBs9FQbIOjC/mrNTEm9JFCOQj3/y/TwyxjYQk/SaUFGWuYgIOmfnKfDWJ2LS3woEJKvUAdaH55NlKkedvoOWNTcHmaWzEalCy4bSAA0knn+ubfHQ0pqQ2P+Eg3BEikMIh7crlVfGTOCh2q+5ccpVNY004YE= sshuser@docker.local
- PASSWORD_ACCESS=true
- USER_PASSWORD=secret-password
- USER_NAME=sshuser
ports:
- "2222:2222"
10 changes: 5 additions & 5 deletions examples/connect-by-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import ssh from 'k6/x/ssh';

export default function () {
ssh.connect({
username: 'YOUR_USERNAME',
host: "YOUR_HOST",
password: "YOUR_PASSWORD",
port: 22
username: 'sshuser',
password: 'secret-password',
host: 'localhost',
port: 2222
})
console.log(ssh.run('pwd'))
console.log(ssh.run('ls -la'))
}
}
10 changes: 5 additions & 5 deletions examples/connect-by-rsa-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import ssh from 'k6/x/ssh';

export default function () {
ssh.connect({
username: 'USERNAME',
host: "HOST_ADDRESS",
port: 22,
rsa_key: "PRIVATE_KEY_PATH" // "~/.ssh/id_rsa" by default
username: 'sshuser',
host: 'localhost',
port: 2222,
rsa_key: 'examples/example_rsa' // "~/.ssh/id_rsa" by default
})
console.log(ssh.run('pwd'))
console.log(ssh.run('ls -la'))
}
}
38 changes: 38 additions & 0 deletions examples/example_rsa
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAxY/jDccWzV4xwTOjPG7SJHgKHi5BreX5JpQFu5WA3ESEI9OhV9Eh
livsi9pB2OrMSSW5sXIUpm+CfwSZB2Ntvjrlo8Xzv2CBC932lpsGyEoD55Mu0e+yFuzPeT
gczkL1l79gF1JV2raoOhg5ngkJaix83yoMFB6LD+tbRjJxX/DRTrQTSICqaKTg0qg93qu/
W7///TR7tMW2o4Xi9NWIN127xWCpaNLYb2CE6rwvpF/vivT8q8EivyzxiFtMal7xRMJQ6j
nEqyG35M0T5HKOv9wDXz62A5Z09TKU3DyRh99cJPOQFDxOmsStAi+L7BCAq4ZlyX39oakS
h7wIzIVPnXh5W9wwjMCfHZBabkQbPRUGyDowv5qzUxJvSRQjkI9/8v08MsY2EJP0mlBRlr
mICDpn5ynw1idi0t8KBCSr1AHWh+eTZSpHnb6DljU3B5mlsxGpQsuG0gANJJ5/rm3x0NKa
kNj/hINwRIpDCIe3K5VXxkzgodqvuXHKVTWNNOGBAAAFiJ7TNvSe0zb0AAAAB3NzaC1yc2
EAAAGBAMWP4w3HFs1eMcEzozxu0iR4Ch4uQa3l+SaUBbuVgNxEhCPToVfRIZYr7IvaQdjq
zEklubFyFKZvgn8EmQdjbb465aPF879ggQvd9pabBshKA+eTLtHvshbsz3k4HM5C9Ze/YB
dSVdq2qDoYOZ4JCWosfN8qDBQeiw/rW0YycV/w0U60E0iAqmik4NKoPd6rv1u///00e7TF
tqOF4vTViDddu8VgqWjS2G9ghOq8L6Rf74r0/KvBIr8s8YhbTGpe8UTCUOo5xKsht+TNE+
Ryj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yN/HdFrtpX9n7zmXPwUdINSxLGhrrdW42HdHJbZb8ATs7l6c/1
kea/fUXttcC4JIDzm3hpSHNHZFpV3VHh9oOXP9XnX5p9bOwN1Z/azTT3mogaO/P1IE49KV
szF+HZ9xiE2bYpBjGsr4EmM/9SVsvc5yHbd15FYkYK/gx2J9ekxfVUYajO5a9HOvTCg27d
1ws+kZz4FO55xERf7HXDAZbGsVX9a7AAAAwQDVdq/RyqAqQsh+fNSBpVcmzrx+pyciKbMy
8Ne3Tie2VWH58Au8AN/yHL5mTbB01WObMqsWuU6cK25+IKHcal0fwnB5N5sdQCqwHYl/CI
MqZIXfxWakLA1STaFbx6vWWOlUJzdg/d0+uHexCn8wFBlkH5oCAEBTjc1RSCO1v6SGWqft
W0g5qlt2o5U9XonzN2dDx1Lo5WDfUeYB6oY9Lxv5+PgRaCDTLm1oSnn+QaZso+0nibfQBl
Aio+5c5/veSvMAAAARcGF1bEBraXNtYWMubG9jYWwBAg==
-----END OPENSSH PRIVATE KEY-----
35 changes: 19 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
module github.com/grafana/xk6-ssh

go 1.17
go 1.19

require (
go.k6.io/k6 v0.36.0
golang.org/x/crypto v0.0.0-20210503195802-e9a32991a82e
go.k6.io/k6 v0.43.1
golang.org/x/crypto v0.7.0
)

require (
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
github.com/dop251/goja v0.0.0-20220110113543-261677941f3c // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/dlclark/regexp2 v1.8.1 // indirect
github.com/dop251/goja v0.0.0-20230304130813-e2f543bf4b4c // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/afero v1.1.2 // indirect
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect
golang.org/x/text v0.3.7-0.20210503195748-5c7c50ebbd4f // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/guregu/null.v3 v3.3.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/guregu/null.v3 v3.5.0 // indirect
)
Loading