diff --git a/backend/go.mod b/backend/go.mod index b8b8169a..7f3ae5d1 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,6 +1,6 @@ module github.com/eko/authz/backend -go 1.24 +go 1.24.0 toolchain go1.24.1 @@ -31,7 +31,7 @@ require ( go.uber.org/fx v1.23.0 golang.org/x/crypto v0.37.0 golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 - golang.org/x/oauth2 v0.29.0 + golang.org/x/oauth2 v0.32.0 google.golang.org/grpc v1.72.0 google.golang.org/protobuf v1.36.6 gorm.io/datatypes v1.2.5 diff --git a/backend/go.sum b/backend/go.sum index cc575f73..3655387a 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -42,8 +42,6 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cucumber/gherkin/go/v26 v26.2.0 h1:EgIjePLWiPeslwIWmNQ3XHcypPsWAHoMCz/YEBKP4GI= github.com/cucumber/gherkin/go/v26 v26.2.0/go.mod h1:t2GAPnB8maCT4lkHL99BDCVNzCh1d7dBhCLt150Nr/0= -github.com/cucumber/godog v0.13.0 h1:KvX9kNWmAJwp882HmObGOyBbNUP5SXQ+SDLNajsuV7A= -github.com/cucumber/godog v0.13.0/go.mod h1:FX3rzIDybWABU4kuIXLZ/qtqEe1Ac5RdXmqvACJOces= github.com/cucumber/godog v0.15.0 h1:51AL8lBXF3f0cyA5CV4TnJFCTHpgiy+1x1Hb3TtZUmo= github.com/cucumber/godog v0.15.0/go.mod h1:FX3rzIDybWABU4kuIXLZ/qtqEe1Ac5RdXmqvACJOces= github.com/cucumber/messages/go/v21 v21.0.1 h1:wzA0LxwjlWQYZd32VTlAVDTkW6inOFmSM+RuOwHZiMI= @@ -114,13 +112,11 @@ github.com/gofiber/fiber/v2 v2.52.6/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPArei github.com/gofiber/swagger v1.1.1 h1:FZVhVQQ9s1ZKLHL/O0loLh49bYB5l1HEAgxDlcTtkRA= github.com/gofiber/swagger v1.1.1/go.mod h1:vtvY/sQAMc/lGTUCg0lqmBL7Ht9O7uzChpbvJeJQINw= github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI= github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -184,7 +180,6 @@ github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-memdb v1.3.4 h1:XSL3NR682X/cVk2IeV0d70N4DZ9ljI885xAEU8IoK3c= github.com/hashicorp/go-memdb v1.3.4/go.mod h1:uBTr1oQbtuMgd1SSGoR8YV27eT3sBHbYiNm53bMpgSg= github.com/hashicorp/go-memdb v1.3.5 h1:b3taDMxCBCBVgyRrS1AZVHO14ubMYZB++QpNhBg+Nyo= github.com/hashicorp/go-memdb v1.3.5/go.mod h1:8IVKKBkVe+fxFgdFOYxzQQNjz+sWCyHCdIC/+5+Vy1Y= @@ -208,7 +203,6 @@ github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= @@ -362,7 +356,6 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -507,8 +500,8 @@ golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= -golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= +golang.org/x/oauth2 v0.32.0 h1:jsCblLleRMDrxMN29H3z/k1KliIvpLgCkE6R8FXXNgY= +golang.org/x/oauth2 v0.32.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/backend/vendor/github.com/cucumber/godog/.gitignore b/backend/vendor/github.com/cucumber/godog/.gitignore index 76481388..bd77fc9f 100644 --- a/backend/vendor/github.com/cucumber/godog/.gitignore +++ b/backend/vendor/github.com/cucumber/godog/.gitignore @@ -8,4 +8,6 @@ Gopkg.toml .idea .vscode -_artifacts \ No newline at end of file +_artifacts + +vendor diff --git a/backend/vendor/github.com/cucumber/godog/CHANGELOG.md b/backend/vendor/github.com/cucumber/godog/CHANGELOG.md index d0718848..11558f10 100644 --- a/backend/vendor/github.com/cucumber/godog/CHANGELOG.md +++ b/backend/vendor/github.com/cucumber/godog/CHANGELOG.md @@ -8,6 +8,38 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt ## Unreleased +## [v0.15.0] + +### Added +- Improved the type checking of step return types and improved the error messages - ([647](https://github.com/cucumber/godog/pull/647) - [johnlon](https://github.com/johnlon)) +- Ambiguous step definitions will now be detected when strict mode is activated - ([636](https://github.com/cucumber/godog/pull/636)/([648](https://github.com/cucumber/godog/pull/648) - [johnlon](https://github.com/johnlon)) +- Provide support for attachments / embeddings including a new example in the examples dir - ([623](https://github.com/cucumber/godog/pull/623) - [johnlon](https://github.com/johnlon)) + +### Changed +- Formatters now have a `Close` method and associated `io.Writer` changed to `io.WriteCloser`. + +## [v0.14.1] + +### Added +- Provide testing.T-compatible interface on test context, allowing usage of assertion libraries such as testify's assert/require - ([571](https://github.com/cucumber/godog/pull/571) - [mrsheepuk](https://github.com/mrsheepuk)) +- Created releasing guidelines - ([608](https://github.com/cucumber/godog/pull/608) - [glibas](https://github.com/glibas)) + +### Fixed +- Step duration calculation - ([616](https://github.com/cucumber/godog/pull/616) - [iaroslav-ciupin](https://github.com/iaroslav-ciupin)) +- Invalid memory address or nil pointer dereference in RetrieveFeatures - ([566](https://github.com/cucumber/godog/pull/566) - [corneldamian](https://github.com/corneldamian)) + +## [v0.14.0] +### Added +- Improve ErrSkip handling, add test for Summary and operations order ([584](https://github.com/cucumber/godog/pull/584) - [vearutop](https://github.com/vearutop)) + +### Fixed +- Remove line overwriting for scenario outlines in cucumber formatter ([605](https://github.com/cucumber/godog/pull/605) - [glibas](https://github.com/glibas)) +- Remove duplicate warning message ([590](https://github.com/cucumber/godog/pull/590) - [vearutop](https://github.com/vearutop)) +- updated base formatter to set a scenario as passed unless there exist ([582](https://github.com/cucumber/godog/pull/582) - [roskee](https://github.com/roskee)) + +### Changed +- Update test.yml ([583](https://github.com/cucumber/godog/pull/583) - [vearutop](https://github.com/vearutop)) + ## [v0.13.0] ### Added - Support for reading feature files from an `fs.FS` ([550](https://github.com/cucumber/godog/pull/550) - [tigh-latte](https://github.com/tigh-latte)) @@ -209,6 +241,9 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt ### Changed - Changed code references to DATA-DOG/godog to cucumber/godog to help get things building correctly. ([mxygem](https://github.com/mxygem)) +[v0.15.0]: https://github.com/cucumber/godog/compare/v0.14.1...v0.15.0 +[v0.14.1]: https://github.com/cucumber/godog/compare/v0.14.0...v0.14.1 +[v0.14.0]: https://github.com/cucumber/godog/compare/v0.13.0...v0.14.0 [v0.13.0]: https://github.com/cucumber/godog/compare/v0.12.6...v0.13.0 [v0.12.6]: https://github.com/cucumber/godog/compare/v0.12.5...v0.12.6 [v0.12.5]: https://github.com/cucumber/godog/compare/v0.12.4...v0.12.5 diff --git a/backend/vendor/github.com/cucumber/godog/CONTRIBUTING.md b/backend/vendor/github.com/cucumber/godog/CONTRIBUTING.md index 44678225..c21ee426 100644 --- a/backend/vendor/github.com/cucumber/godog/CONTRIBUTING.md +++ b/backend/vendor/github.com/cucumber/godog/CONTRIBUTING.md @@ -7,7 +7,7 @@ to give you a grounding in some of the basic concepts. You could also watch [thi We want you to feel safe to make mistakes, and ask questions. If anything in this guide or anywhere else in the codebase doesn't make sense to you, please let us know! It's through your feedback that we can make this codebase more welcoming, so we'll be glad to hear thoughts. -You can chat with us in the [#committers-go](https://cucumberbdd.slack.com/archives/CA5NJPDJ4) channel in our [community Slack], or feel free to [raise an issue] if you're experiencing any friction trying make your contribution. +You can chat with us in the `#committers` channel in our [community Discord](https://cucumber.io/docs/community/get-in-touch/#discord), or feel free to [raise an issue] if you're experiencing any friction trying make your contribution. ## Setup @@ -20,7 +20,7 @@ Once that's done, try running the tests: If everything passes, you're ready to hack! [install go]: https://golang.org/doc/install -[community Slack]: https://cucumber.io/community#slack +[community Discord]: https://cucumber.io/community#discord [raise an issue]: https://github.com/cucumber/godog/issues/new/choose ## Changing dependencies diff --git a/backend/vendor/github.com/cucumber/godog/Makefile b/backend/vendor/github.com/cucumber/godog/Makefile index 01bbc5c4..aefccb13 100644 --- a/backend/vendor/github.com/cucumber/godog/Makefile +++ b/backend/vendor/github.com/cucumber/godog/Makefile @@ -2,21 +2,32 @@ VERS ?= $(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match) -FOUND_GO_VERSION := $(shell go version) -EXPECTED_GO_VERSION = 1.17 +GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) +MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 +MINIMUM_SUPPORTED_GO_MINOR_VERSION = 16 +GO_VERSION_VALIDATION_ERR_MSG = Go version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) + .PHONY: check-go-version check-go-version: - @$(if $(findstring ${EXPECTED_GO_VERSION}, ${FOUND_GO_VERSION}),(exit 0),(echo Wrong go version! Please install ${EXPECTED_GO_VERSION}; exit 1)) + @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + exit 0 ;\ + elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + fi test: check-go-version @echo "running all tests" - @go install ./... @go fmt ./... - @go run honnef.co/go/tools/cmd/staticcheck@v0.2.2 github.com/cucumber/godog - @go run honnef.co/go/tools/cmd/staticcheck@v0.2.2 github.com/cucumber/godog/cmd/godog + @go run honnef.co/go/tools/cmd/staticcheck@v0.4.7 github.com/cucumber/godog + @go run honnef.co/go/tools/cmd/staticcheck@v0.4.7 github.com/cucumber/godog/cmd/godog go vet ./... go test -race ./... - godog -f progress -c 4 + go run ./cmd/godog -f progress -c 4 gherkin: @if [ -z "$(VERS)" ]; then echo "Provide gherkin version like: 'VERS=commit-hash'"; exit 1; fi diff --git a/backend/vendor/github.com/cucumber/godog/README.md b/backend/vendor/github.com/cucumber/godog/README.md index 494f4426..fbe765f5 100644 --- a/backend/vendor/github.com/cucumber/godog/README.md +++ b/backend/vendor/github.com/cucumber/godog/README.md @@ -46,15 +46,11 @@ Godog is a community driven Open Source Project within the Cucumber organization See the [contributing guide] for more detail on how to get started. -## Getting help - -We have a [community Slack] where you can chat with other users, developers, and BDD practitioners. +See the [releasing guide] for release flow details. -Here are some useful channels to try: +## Getting help -- [#help-godog](https://cucumberbdd.slack.com/archives/CTNL1JCVA) - General Godog Adoption Help -- [#committers-go](https://cucumberbdd.slack.com/archives/CA5NJPDJ4) - Golang focused Cucumber Contributors -- [#committers](https://cucumberbdd.slack.com/archives/C62D0FK0E) - General Cucumber Contributors +We have a [community Discord](https://cucumber.io/docs/community/get-in-touch/#discord) where you can chat with other users, developers, and BDD practitioners. ## Examples @@ -290,6 +286,10 @@ When steps are orthogonal and small, you can combine them just like you do with `TestFeatures` acts as a regular Go test, so you can leverage your IDE facilities to run and debug it. +### Attachments + +An example showing how to make attachments (aka embeddings) to the results is shown in [_examples/attachments](/_examples/attachments/) + ## Code of Conduct Everyone interacting in this codebase and issue tracker is expected to follow the Cucumber [code of conduct](https://github.com/cucumber/cucumber/blob/master/CODE_OF_CONDUCT.md). @@ -493,31 +493,12 @@ If you want to filter scenarios by tags, you can use the `-t=` or `- A more extensive example can be [found here](/_examples/assert-godogs). ```go -func thereShouldBeRemaining(remaining int) error { - return assertExpectedAndActual( - assert.Equal, Godogs, remaining, - "Expected %d godogs to be remaining, but there is %d", remaining, Godogs, - ) -} - -// assertExpectedAndActual is a helper function to allow the step function to call -// assertion functions where you want to compare an expected and an actual value. -func assertExpectedAndActual(a expectedAndActualAssertion, expected, actual interface{}, msgAndArgs ...interface{}) error { - var t asserter - a(&t, expected, actual, msgAndArgs...) - return t.err -} - -type expectedAndActualAssertion func(t assert.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool - -// asserter is used to be able to retrieve the error reported by the called assertion -type asserter struct { - err error -} - -// Errorf is used by the called assertion to report an error -func (a *asserter) Errorf(format string, args ...interface{}) { - a.err = fmt.Errorf(format, args...) +func thereShouldBeRemaining(ctx context.Context, remaining int) error { + assert.Equal( + godog.T(ctx), Godogs, remaining, + "Expected %d godogs to be remaining, but there is %d", remaining, Godogs, + ) + return nil } ``` @@ -595,4 +576,8 @@ A simple example can be [found here](/_examples/custom-formatter). [cucumber]: https://cucumber.io/ "Behavior driven development framework" [license]: https://en.wikipedia.org/wiki/MIT_License "The MIT license" [contributing guide]: https://github.com/cucumber/godog/blob/main/CONTRIBUTING.md -[community Slack]: https://cucumber.io/community#slack +[releasing guide]: https://github.com/cucumber/godog/blob/main/RELEASING.md +[community Discord]: https://cucumber.io/community#discord + + + diff --git a/backend/vendor/github.com/cucumber/godog/RELEASING.md b/backend/vendor/github.com/cucumber/godog/RELEASING.md new file mode 100644 index 00000000..cba24365 --- /dev/null +++ b/backend/vendor/github.com/cucumber/godog/RELEASING.md @@ -0,0 +1,67 @@ +# Releasing Guidelines for Cucumber Godog + +This document provides guidelines for releasing new versions of Cucumber Godog. Follow these steps to ensure a smooth and consistent release process. + +## Versioning + +Cucumber Godog follows [Semantic Versioning]. Version numbers are in the format `MAJOR.MINOR.PATCH`. + +### Current (for v0.MINOR.PATCH) + +- **MINOR**: Incompatible API changes. +- **PATCH**: Backward-compatible new features and bug fixes. + +### After v1.X.X release + +- **MAJOR**: Incompatible API changes. +- **MINOR**: Backward-compatible new features. +- **PATCH**: Backward-compatible bug fixes. + +## Release Process + +1. **Update Changelog:** + - Open `CHANGELOG.md` and add an entry for the upcoming release formatting according to the principles of [Keep A CHANGELOG]. + - Include details about new features, enhancements, and bug fixes. + +2. **Run Tests:** + - Run the test suite to ensure all existing features are working as expected. + +3. **Manual Testing for Backwards Compatibility:** + - Manually test the new release with external libraries that depend on Cucumber Godog. + - Look for any potential backwards compatibility issues, especially with widely-used libraries. + - Address any identified issues before proceeding. + +4. **Create Release on GitHub:** + - Go to the [Releases] page on GitHub. + - Click on "Draft a new release." + - Tag version should be set to the new tag vMAJOR.MINOR.PATCH + - Title the release using the version number (e.g., "vMAJOR.MINOR.PATCH"). + - Click 'Generate release notes' + +5. **Publish Release:** + - Click "Publish release" to make the release public. + +6. **Announce the Release:** + - Make an announcement on relevant communication channels (e.g., [community Discord]) about the new release. + +## Additional Considerations + +- **Documentation:** + - Update the project documentation on the [website], if applicable. + +- **Deprecation Notices:** + - If any features are deprecated, clearly document them in the release notes and provide guidance on migration. + +- **Compatibility:** + - Clearly state any compatibility requirements or changes in the release notes. + +- **Feedback:** + - Encourage users to provide feedback and report any issues with the new release. + +Following these guidelines, including manual testing with external libraries, will help ensure a thorough release process for Cucumber Godog, allowing detection and resolution of potential backwards compatibility issues before tagging the release. + +[community Discord]: https://cucumber.io/community#discord +[website]: https://cucumber.github.io/godog/ +[Releases]: https://github.com/cucumber/godog/releases +[Semantic Versioning]: http://semver.org +[Keep A CHANGELOG]: http://keepachangelog.com \ No newline at end of file diff --git a/backend/vendor/github.com/cucumber/godog/flags.go b/backend/vendor/github.com/cucumber/godog/flags.go index 14782e16..45efbfec 100644 --- a/backend/vendor/github.com/cucumber/godog/flags.go +++ b/backend/vendor/github.com/cucumber/godog/flags.go @@ -121,7 +121,7 @@ func BindFlags(prefix string, set *flag.FlagSet, opt *Options) { set.BoolVar(&opt.ShowStepDefinitions, prefix+"definitions", defShowStepDefinitions, "Print all available step definitions.") set.BoolVar(&opt.ShowStepDefinitions, prefix+"d", defShowStepDefinitions, "Print all available step definitions.") set.BoolVar(&opt.StopOnFailure, prefix+"stop-on-failure", defStopOnFailure, "Stop processing on first failed scenario.") - set.BoolVar(&opt.Strict, prefix+"strict", defStrict, "Fail suite when there are pending or undefined steps.") + set.BoolVar(&opt.Strict, prefix+"strict", defStrict, "Fail suite when there are pending or undefined or ambiguous steps.") set.BoolVar(&opt.NoColors, prefix+"no-colors", defNoColors, "Disable ansi colors.") set.Var(&randomSeed{&opt.Randomize}, prefix+"random", descRandomOption) set.BoolVar(&opt.ShowHelp, "godog.help", false, "Show usage help.") diff --git a/backend/vendor/github.com/cucumber/godog/formatters/fmt.go b/backend/vendor/github.com/cucumber/godog/formatters/fmt.go index aa098b0f..fec96961 100644 --- a/backend/vendor/github.com/cucumber/godog/formatters/fmt.go +++ b/backend/vendor/github.com/cucumber/godog/formatters/fmt.go @@ -70,6 +70,7 @@ type Formatter interface { Skipped(*messages.Pickle, *messages.PickleStep, *StepDefinition) Undefined(*messages.Pickle, *messages.PickleStep, *StepDefinition) Pending(*messages.Pickle, *messages.PickleStep, *StepDefinition) + Ambiguous(*messages.Pickle, *messages.PickleStep, *StepDefinition, error) Summary() } diff --git a/backend/vendor/github.com/cucumber/godog/internal/flags/flags.go b/backend/vendor/github.com/cucumber/godog/internal/flags/flags.go index 2d4a60d1..1bd67e59 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/flags/flags.go +++ b/backend/vendor/github.com/cucumber/godog/internal/flags/flags.go @@ -39,7 +39,7 @@ built-in formatters are: flagSet.BoolVarP(&opts.ShowStepDefinitions, prefix+"definitions", "d", opts.ShowStepDefinitions, "print all available step definitions") flagSet.BoolVar(&opts.StopOnFailure, prefix+"stop-on-failure", opts.StopOnFailure, "stop processing on first failed scenario") - flagSet.BoolVar(&opts.Strict, prefix+"strict", opts.Strict, "fail suite when there are pending or undefined steps") + flagSet.BoolVar(&opts.Strict, prefix+"strict", opts.Strict, "fail suite when there are pending or undefined or ambiguous steps") flagSet.Int64Var(&opts.Randomize, prefix+"random", opts.Randomize, `randomly shuffle the scenario execution order --random diff --git a/backend/vendor/github.com/cucumber/godog/internal/flags/options.go b/backend/vendor/github.com/cucumber/godog/internal/flags/options.go index fed059a7..5ca40f91 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/flags/options.go +++ b/backend/vendor/github.com/cucumber/godog/internal/flags/options.go @@ -38,7 +38,7 @@ type Options struct { // Stops on the first failure StopOnFailure bool - // Fail suite when there are pending or undefined steps + // Fail suite when there are pending or undefined or ambiguous steps Strict bool // Forces ansi color stripping diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt.go index 883bc740..3efe1f46 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt.go @@ -36,6 +36,7 @@ var ( skipped = models.Skipped undefined = models.Undefined pending = models.Pending + ambiguous = models.Ambiguous ) type sortFeaturesByName []*models.Feature diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_base.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_base.go index 2166509e..607a1c06 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_base.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_base.go @@ -85,10 +85,14 @@ func (f *Base) Failed(*messages.Pickle, *messages.PickleStep, *formatters.StepDe func (f *Base) Pending(*messages.Pickle, *messages.PickleStep, *formatters.StepDefinition) { } +// Ambiguous captures ambiguous step. +func (f *Base) Ambiguous(*messages.Pickle, *messages.PickleStep, *formatters.StepDefinition, error) { +} + // Summary renders summary information. func (f *Base) Summary() { var totalSc, passedSc, undefinedSc int - var totalSt, passedSt, failedSt, skippedSt, pendingSt, undefinedSt int + var totalSt, passedSt, failedSt, skippedSt, pendingSt, undefinedSt, ambiguousSt int pickleResults := f.Storage.MustGetPickleResults() for _, pr := range pickleResults { @@ -106,11 +110,13 @@ func (f *Base) Summary() { switch sr.Status { case passed: - prStatus = passed passedSt++ case failed: prStatus = failed failedSt++ + case ambiguous: + prStatus = ambiguous + ambiguousSt++ case skipped: skippedSt++ case undefined: @@ -141,6 +147,10 @@ func (f *Base) Summary() { parts = append(parts, yellow(fmt.Sprintf("%d pending", pendingSt))) steps = append(steps, yellow(fmt.Sprintf("%d pending", pendingSt))) } + if ambiguousSt > 0 { + parts = append(parts, yellow(fmt.Sprintf("%d ambiguous", ambiguousSt))) + steps = append(steps, yellow(fmt.Sprintf("%d ambiguous", ambiguousSt))) + } if undefinedSt > 0 { parts = append(parts, yellow(fmt.Sprintf("%d undefined", undefinedSc))) steps = append(steps, yellow(fmt.Sprintf("%d undefined", undefinedSt))) diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_cucumber.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_cucumber.go index 8adbfcba..31380c97 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_cucumber.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_cucumber.go @@ -12,6 +12,7 @@ package formatters */ import ( + "encoding/base64" "encoding/json" "fmt" "io" @@ -100,7 +101,8 @@ func (f *Cuke) buildCukeElements(pickles []*messages.Pickle) (res []cukeElement) cukeStep.Result.Duration = &d if stepResult.Status == undefined || stepResult.Status == pending || - stepResult.Status == skipped { + stepResult.Status == skipped || + stepResult.Status == ambiguous { cukeStep.Result.Duration = nil } @@ -139,14 +141,21 @@ type cukeMatch struct { Location string `json:"location"` } +type cukeEmbedding struct { + Name string `json:"name"` + MimeType string `json:"mime_type"` + Data string `json:"data"` +} + type cukeStep struct { - Keyword string `json:"keyword"` - Name string `json:"name"` - Line int `json:"line"` - Docstring *cukeDocstring `json:"doc_string,omitempty"` - Match cukeMatch `json:"match"` - Result cukeResult `json:"result"` - DataTable []*cukeDataTableRow `json:"rows,omitempty"` + Keyword string `json:"keyword"` + Name string `json:"name"` + Line int `json:"line"` + Docstring *cukeDocstring `json:"doc_string,omitempty"` + Match cukeMatch `json:"match"` + Result cukeResult `json:"result"` + DataTable []*cukeDataTableRow `json:"rows,omitempty"` + Embeddings []cukeEmbedding `json:"embeddings,omitempty"` } type cukeDataTableRow struct { @@ -252,10 +261,6 @@ func (f *Cuke) buildCukeStep(pickle *messages.Pickle, stepResult models.PickleSt step := feature.FindStep(pickleStep.AstNodeIds[0]) line := step.Location.Line - if len(pickle.AstNodeIds) == 2 { - _, row := feature.FindExample(pickle.AstNodeIds[1]) - line = row.Location.Line - } cukeStep.Name = pickleStep.Text cukeStep.Line = int(line) @@ -294,10 +299,25 @@ func (f *Cuke) buildCukeStep(pickle *messages.Pickle, stepResult models.PickleSt cukeStep.Result.Error = stepResult.Err.Error() } - if stepResult.Status == undefined || stepResult.Status == pending { + if stepResult.Status == undefined || stepResult.Status == pending || stepResult.Status == ambiguous { cukeStep.Match.Location = fmt.Sprintf("%s:%d", pickle.Uri, step.Location.Line) } + if stepResult.Attachments != nil { + attachments := []cukeEmbedding{} + + for _, a := range stepResult.Attachments { + attachments = append(attachments, cukeEmbedding{ + Name: a.Name, + Data: base64.StdEncoding.EncodeToString(a.Data), + MimeType: a.MimeType, + }) + } + + if len(attachments) > 0 { + cukeStep.Embeddings = attachments + } + } return cukeStep } diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_events.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_events.go index e264db57..c5ffcb50 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_events.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_events.go @@ -153,6 +153,31 @@ func (f *Events) step(pickle *messages.Pickle, pickleStep *messages.PickleStep) if pickleStepResult.Err != nil { errMsg = pickleStepResult.Err.Error() } + + if pickleStepResult.Attachments != nil { + for _, attachment := range pickleStepResult.Attachments { + + f.event(&struct { + Event string `json:"event"` + Location string `json:"location"` + Timestamp int64 `json:"timestamp"` + ContentEncoding string `json:"contentEncoding"` + FileName string `json:"fileName"` + MimeType string `json:"mimeType"` + Body string `json:"body"` + }{ + "Attachment", + fmt.Sprintf("%s:%d", pickle.Uri, step.Location.Line), + utils.TimeNowFunc().UnixNano() / nanoSec, + messages.AttachmentContentEncoding_BASE64.String(), + attachment.Name, + attachment.MimeType, + string(attachment.Data), + }) + + } + } + f.event(&struct { Event string `json:"event"` Location string `json:"location"` @@ -173,7 +198,7 @@ func (f *Events) step(pickle *messages.Pickle, pickleStep *messages.PickleStep) pickleStepResults := f.Storage.MustGetPickleStepResultsByPickleID(pickle.Id) for _, stepResult := range pickleStepResults { switch stepResult.Status { - case passed, failed, undefined, pending: + case passed, failed, undefined, pending, ambiguous: status = stepResult.Status.String() } } @@ -293,6 +318,16 @@ func (f *Events) Pending(pickle *messages.Pickle, step *messages.PickleStep, mat f.step(pickle, step) } +// Ambiguous captures ambiguous step. +func (f *Events) Ambiguous(pickle *messages.Pickle, step *messages.PickleStep, match *formatters.StepDefinition, err error) { + f.Base.Ambiguous(pickle, step, match, err) + + f.Lock.Lock() + defer f.Lock.Unlock() + + f.step(pickle, step) +} + func (f *Events) scenarioLocation(pickle *messages.Pickle) string { feature := f.Storage.MustGetFeature(pickle.Uri) scenario := feature.FindScenario(pickle.AstNodeIds[0]) diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_junit.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_junit.go index bc6ed270..d7b25170 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_junit.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_junit.go @@ -117,6 +117,12 @@ func (f *JUnit) buildJUNITPackageSuite() JunitPackageSuite { tc.Failure = &junitFailure{ Message: fmt.Sprintf("Step %s: %s", pickleStep.Text, stepResult.Err), } + case ambiguous: + tc.Status = ambiguous.String() + tc.Error = append(tc.Error, &junitError{ + Type: "ambiguous", + Message: fmt.Sprintf("Step %s", pickleStep.Text), + }) case skipped: tc.Error = append(tc.Error, &junitError{ Type: "skipped", diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_multi.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_multi.go index e23e6ade..001c9980 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_multi.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_multi.go @@ -97,6 +97,13 @@ func (r repeater) Pending(pickle *messages.Pickle, step *messages.PickleStep, de } } +// Ambiguous triggers Ambiguous for all added formatters. +func (r repeater) Ambiguous(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition, err error) { + for _, f := range r { + f.Ambiguous(pickle, step, definition, err) + } +} + // Summary triggers Summary for all added formatters. func (r repeater) Summary() { for _, f := range r { diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_pretty.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_pretty.go index e7b9e325..91dbc0cb 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_pretty.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_pretty.go @@ -114,6 +114,16 @@ func (f *Pretty) Failed(pickle *messages.Pickle, step *messages.PickleStep, matc f.printStep(pickle, step) } +// Failed captures failed step. +func (f *Pretty) Ambiguous(pickle *messages.Pickle, step *messages.PickleStep, match *formatters.StepDefinition, err error) { + f.Base.Ambiguous(pickle, step, match, err) + + f.Lock.Lock() + defer f.Lock.Unlock() + + f.printStep(pickle, step) +} + // Pending captures pending step. func (f *Pretty) Pending(pickle *messages.Pickle, step *messages.PickleStep, match *formatters.StepDefinition) { f.Base.Pending(pickle, step, match) @@ -269,6 +279,9 @@ func (f *Pretty) printOutlineExample(pickle *messages.Pickle, backgroundSteps in case result.Status == failed: errorMsg = result.Err.Error() clr = result.Status.Color() + case result.Status == ambiguous: + errorMsg = result.Err.Error() + clr = result.Status.Color() case result.Status == undefined || result.Status == pending: clr = result.Status.Color() case result.Status == skipped && clr == nil: diff --git a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_progress.go b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_progress.go index 23086963..9722ef7a 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_progress.go +++ b/backend/vendor/github.com/cucumber/godog/internal/formatters/fmt_progress.go @@ -98,6 +98,8 @@ func (f *Progress) step(pickleStepID string) { fmt.Fprint(f.out, red("F")) case undefined: fmt.Fprint(f.out, yellow("U")) + case ambiguous: + fmt.Fprint(f.out, yellow("A")) case pending: fmt.Fprint(f.out, yellow("P")) } @@ -149,6 +151,16 @@ func (f *Progress) Failed(pickle *messages.Pickle, step *messages.PickleStep, ma f.step(step.Id) } +// Ambiguous steps. +func (f *Progress) Ambiguous(pickle *messages.Pickle, step *messages.PickleStep, match *formatters.StepDefinition, err error) { + f.Base.Ambiguous(pickle, step, match, err) + + f.Lock.Lock() + defer f.Lock.Unlock() + + f.step(step.Id) +} + // Pending captures pending step. func (f *Progress) Pending(pickle *messages.Pickle, step *messages.PickleStep, match *formatters.StepDefinition) { f.Base.Pending(pickle, step, match) diff --git a/backend/vendor/github.com/cucumber/godog/internal/models/results.go b/backend/vendor/github.com/cucumber/godog/internal/models/results.go index 461a5b8a..9c7f98d7 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/models/results.go +++ b/backend/vendor/github.com/cucumber/godog/internal/models/results.go @@ -18,6 +18,13 @@ type PickleResult struct { StartedAt time.Time } +// PickleAttachment ... +type PickleAttachment struct { + Name string + MimeType string + Data []byte +} + // PickleStepResult ... type PickleStepResult struct { Status StepResultStatus @@ -28,11 +35,27 @@ type PickleStepResult struct { PickleStepID string Def *StepDefinition + + Attachments []PickleAttachment } // NewStepResult ... -func NewStepResult(pickleID, pickleStepID string, match *StepDefinition) PickleStepResult { - return PickleStepResult{FinishedAt: utils.TimeNowFunc(), PickleID: pickleID, PickleStepID: pickleStepID, Def: match} +func NewStepResult( + status StepResultStatus, + pickleID, pickleStepID string, + match *StepDefinition, + attachments []PickleAttachment, + err error, +) PickleStepResult { + return PickleStepResult{ + Status: status, + FinishedAt: utils.TimeNowFunc(), + Err: err, + PickleID: pickleID, + PickleStepID: pickleStepID, + Def: match, + Attachments: attachments, + } } // StepResultStatus ... @@ -49,6 +72,8 @@ const ( Undefined // Pending ... Pending + // Ambiguous ... + Ambiguous ) // Color ... @@ -78,6 +103,8 @@ func (st StepResultStatus) String() string { return "undefined" case Pending: return "pending" + case Ambiguous: + return "ambiguous" default: return "unknown" } diff --git a/backend/vendor/github.com/cucumber/godog/internal/models/stepdef.go b/backend/vendor/github.com/cucumber/godog/internal/models/stepdef.go index 497ffc7c..90ffef54 100644 --- a/backend/vendor/github.com/cucumber/godog/internal/models/stepdef.go +++ b/backend/vendor/github.com/cucumber/godog/internal/models/stepdef.go @@ -16,9 +16,9 @@ var typeOfBytes = reflect.TypeOf([]byte(nil)) // matchable errors var ( - ErrUnmatchedStepArgumentNumber = errors.New("func received more arguments than expected") + ErrUnmatchedStepArgumentNumber = errors.New("func expected more arguments than given") ErrCannotConvert = errors.New("cannot convert argument") - ErrUnsupportedArgumentType = errors.New("unsupported argument type") + ErrUnsupportedParameterType = errors.New("func has unsupported parameter type") ) // StepDefinition ... @@ -36,6 +36,9 @@ type StepDefinition struct { var typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem() // Run a step with the matched arguments using reflect +// Returns one of ... +// (context, error) +// (context, godog.Steps) func (sd *StepDefinition) Run(ctx context.Context) (context.Context, interface{}) { var values []reflect.Value @@ -161,7 +164,8 @@ func (sd *StepDefinition) Run(ctx context.Context) (context.Context, interface{} return ctx, fmt.Errorf(`%w %d: "%v" of type "%T" to *messages.PickleTable`, ErrCannotConvert, i, arg, arg) default: - return ctx, fmt.Errorf("%w: the argument %d type %T is not supported %s", ErrUnsupportedArgumentType, i, arg, param.Elem().String()) + // the error here is that the declared function has an unsupported param type - really this ought to be trapped at registration ti,e + return ctx, fmt.Errorf("%w: the data type of parameter %d type *%s is not supported", ErrUnsupportedParameterType, i, param.Elem().String()) } case reflect.Slice: switch param { @@ -172,10 +176,13 @@ func (sd *StepDefinition) Run(ctx context.Context) (context.Context, interface{} } values = append(values, reflect.ValueOf([]byte(s))) default: - return ctx, fmt.Errorf("%w: the slice argument %d type %s is not supported", ErrUnsupportedArgumentType, i, param.Kind()) + // the problem is the function decl is not using a support slice type as the param + return ctx, fmt.Errorf("%w: the slice parameter %d type []%s is not supported", ErrUnsupportedParameterType, i, param.Elem().Kind()) } + case reflect.Struct: + return ctx, fmt.Errorf("%w: the struct parameter %d type %s is not supported", ErrUnsupportedParameterType, i, param.String()) default: - return ctx, fmt.Errorf("%w: the argument %d type %s is not supported", ErrUnsupportedArgumentType, i, param.Kind()) + return ctx, fmt.Errorf("%w: the parameter %d type %s is not supported", ErrUnsupportedParameterType, i, param.Kind()) } } @@ -184,17 +191,43 @@ func (sd *StepDefinition) Run(ctx context.Context) (context.Context, interface{} return ctx, nil } + // Note that the step fn return types were validated at Initialise in test_context.go stepWithKeyword() + + // single return value may be one of ... + // error + // context.Context + // godog.Steps + result0 := res[0].Interface() if len(res) == 1 { - r := res[0].Interface() - if ctx, ok := r.(context.Context); ok { + // if the single return value is a context then just return it + if ctx, ok := result0.(context.Context); ok { return ctx, nil } - return ctx, res[0].Interface() + // return type is presumably one of nil, "error" or "Steps" so place it into second return position + return ctx, result0 + } + + // multi-value value return must be + // (context, error) and the context value must not be nil + if ctx, ok := result0.(context.Context); ok { + return ctx, res[1].Interface() + } + + result1 := res[1].Interface() + errMsg := "" + if result1 != nil { + errMsg = fmt.Sprintf(", step def also returned an error: %v", result1) + } + + text := sd.StepDefinition.Expr.String() + + if result0 == nil { + panic(fmt.Sprintf("step definition '%v' with return type (context.Context, error) must not return for the context.Context value%s", text, errMsg)) } - return res[0].Interface().(context.Context), res[1].Interface() + panic(fmt.Errorf("step definition '%v' has return type (context.Context, error), but found %v rather than a context.Context value%s", text, result0, errMsg)) } func (sd *StepDefinition) shouldBeString(idx int) (string, error) { diff --git a/backend/vendor/github.com/cucumber/godog/run.go b/backend/vendor/github.com/cucumber/godog/run.go index 09fdee07..405aaff9 100644 --- a/backend/vendor/github.com/cucumber/godog/run.go +++ b/backend/vendor/github.com/cucumber/godog/run.go @@ -361,6 +361,10 @@ func (ts TestSuite) RetrieveFeatures() ([]*models.Feature, error) { } } + if ts.Options.FS == nil { + ts.Options.FS = storage.FS{} + } + if len(opt.Paths) == 0 { inf, err := func() (fs.FileInfo, error) { file, err := opt.FS.Open("features") diff --git a/backend/vendor/github.com/cucumber/godog/suite.go b/backend/vendor/github.com/cucumber/godog/suite.go index 16bfd15e..9a387299 100644 --- a/backend/vendor/github.com/cucumber/godog/suite.go +++ b/backend/vendor/github.com/cucumber/godog/suite.go @@ -21,6 +21,9 @@ var ( contextInterface = reflect.TypeOf((*context.Context)(nil)).Elem() ) +// more than one regex matched the step text +var ErrAmbiguous = fmt.Errorf("ambiguous step definition") + // ErrUndefined is returned in case if step definition was not found var ErrUndefined = fmt.Errorf("step is undefined") @@ -45,6 +48,8 @@ const ( StepUndefined = models.Undefined // StepPending indicates step with pending implementation. StepPending = models.Pending + // StepAmbiguous indicates step text matches more than one step def + StepAmbiguous = models.Ambiguous ) type suite struct { @@ -68,32 +73,81 @@ type suite struct { afterScenarioHandlers []AfterScenarioHook } -func (s *suite) matchStep(step *messages.PickleStep) *models.StepDefinition { - def := s.matchStepTextAndType(step.Text, step.Type) +type Attachment struct { + Body []byte + FileName string + MediaType string +} + +type attachmentKey struct{} + +func Attach(ctx context.Context, attachments ...Attachment) context.Context { + existing := Attachments(ctx) + updated := append(existing, attachments...) + return context.WithValue(ctx, attachmentKey{}, updated) +} + +func Attachments(ctx context.Context) []Attachment { + v := ctx.Value(attachmentKey{}) + + if v == nil { + return []Attachment{} + } + return v.([]Attachment) +} + +func clearAttach(ctx context.Context) context.Context { + return context.WithValue(ctx, attachmentKey{}, nil) +} + +func pickleAttachments(ctx context.Context) []models.PickleAttachment { + + pickledAttachments := []models.PickleAttachment{} + attachments := Attachments(ctx) + + for _, a := range attachments { + pickledAttachments = append(pickledAttachments, models.PickleAttachment{ + Name: a.FileName, + Data: a.Body, + MimeType: a.MediaType, + }) + } + + return pickledAttachments +} + +func (s *suite) matchStep(step *messages.PickleStep) (*models.StepDefinition, error) { + def, err := s.matchStepTextAndType(step.Text, step.Type) + if err != nil { + return nil, err + } + if def != nil && step.Argument != nil { def.Args = append(def.Args, step.Argument) } - return def + return def, nil } func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scenarioErr error, isFirst, isLast bool) (rctx context.Context, err error) { - var ( - match *models.StepDefinition - sr = models.NewStepResult(pickle.Id, step.Id, match) - ) + var match *models.StepDefinition rctx = ctx - sr.Status = StepUndefined // user multistep definitions may panic defer func() { if e := recover(); e != nil { - if err != nil { + pe, isErr := e.(error) + switch { + case isErr && errors.Is(pe, errStopNow): + // FailNow or SkipNow called on dogTestingT, so clear the error to let the normal + // below getTestingT(ctx).isFailed() call handle the reasons. + err = nil + case err != nil: err = &traceError{ msg: fmt.Sprintf("%s: %v", err.Error(), e), stack: callStack(), } - } else { + default: err = &traceError{ msg: fmt.Sprintf("%v", e), stack: callStack(), @@ -101,51 +155,66 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena } } - earlyReturn := scenarioErr != nil || err == ErrUndefined + earlyReturn := scenarioErr != nil || errors.Is(err, ErrUndefined) + + // Check for any calls to Fail on dogT + if err == nil { + err = getTestingT(ctx).isFailed() + } + + status := StepUndefined switch { + case errors.Is(err, ErrAmbiguous): + status = StepAmbiguous case errors.Is(err, ErrPending): - sr.Status = StepPending - case errors.Is(err, ErrSkip) || (err == nil && scenarioErr != nil): - sr.Status = StepSkipped + status = StepPending + case errors.Is(err, ErrSkip), err == nil && scenarioErr != nil: + status = StepSkipped case errors.Is(err, ErrUndefined): - sr.Status = StepUndefined + status = StepUndefined case err != nil: - sr.Status = StepFailed + status = StepFailed case err == nil && scenarioErr == nil: - sr.Status = StepPassed + status = StepPassed } // Run after step handlers. - rctx, err = s.runAfterStepHooks(ctx, step, sr.Status, err) - - shouldFail := s.shouldFail(err) + rctx, err = s.runAfterStepHooks(ctx, step, status, err) // Trigger after scenario on failing or last step to attach possible hook error to step. - if !s.shouldFail(scenarioErr) && (isLast || shouldFail) { + if !s.shouldFail(scenarioErr) && (isLast || s.shouldFail(err)) { rctx, err = s.runAfterScenarioHooks(rctx, pickle, err) } + // extract any accumulated attachments and clear them + pickledAttachments := pickleAttachments(rctx) + rctx = clearAttach(rctx) + if earlyReturn { return } - switch err { - case nil: - sr.Status = models.Passed + switch { + case err == nil: + sr := models.NewStepResult(models.Passed, pickle.Id, step.Id, match, pickledAttachments, nil) s.storage.MustInsertPickleStepResult(sr) - s.fmt.Passed(pickle, step, match.GetInternalStepDefinition()) - case ErrPending: - sr.Status = models.Pending + case errors.Is(err, ErrPending): + sr := models.NewStepResult(models.Pending, pickle.Id, step.Id, match, pickledAttachments, nil) s.storage.MustInsertPickleStepResult(sr) - s.fmt.Pending(pickle, step, match.GetInternalStepDefinition()) + case errors.Is(err, ErrSkip): + sr := models.NewStepResult(models.Skipped, pickle.Id, step.Id, match, pickledAttachments, nil) + s.storage.MustInsertPickleStepResult(sr) + s.fmt.Skipped(pickle, step, match.GetInternalStepDefinition()) + case errors.Is(err, ErrAmbiguous): + sr := models.NewStepResult(models.Ambiguous, pickle.Id, step.Id, match, pickledAttachments, err) + s.storage.MustInsertPickleStepResult(sr) + s.fmt.Ambiguous(pickle, step, match.GetInternalStepDefinition(), err) default: - sr.Status = models.Failed - sr.Err = err + sr := models.NewStepResult(models.Failed, pickle.Id, step.Id, match, pickledAttachments, err) s.storage.MustInsertPickleStepResult(sr) - s.fmt.Failed(pickle, step, match.GetInternalStepDefinition(), err) } }() @@ -158,19 +227,25 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena // run before step handlers ctx, err = s.runBeforeStepHooks(ctx, step, err) - match = s.matchStep(step) + var matchError error + match, matchError = s.matchStep(step) + s.storage.MustInsertStepDefintionMatch(step.AstNodeIds[0], match) - sr.Def = match s.fmt.Defined(pickle, step, match.GetInternalStepDefinition()) if err != nil { - sr = models.NewStepResult(pickle.Id, step.Id, match) - sr.Status = models.Failed - s.storage.MustInsertPickleStepResult(sr) + pickledAttachments := pickleAttachments(ctx) + ctx = clearAttach(ctx) + sr := models.NewStepResult(models.Failed, pickle.Id, step.Id, match, pickledAttachments, nil) + s.storage.MustInsertPickleStepResult(sr) return ctx, err } + if matchError != nil { + return ctx, matchError + } + if ctx, undef, err := s.maybeUndefined(ctx, step.Text, step.Argument, step.Type); err != nil { return ctx, err } else if len(undef) > 0 { @@ -186,11 +261,12 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena Nested: match.Nested, Undefined: undef, } - sr.Def = match } - sr = models.NewStepResult(pickle.Id, step.Id, match) - sr.Status = models.Undefined + pickledAttachments := pickleAttachments(ctx) + ctx = clearAttach(ctx) + + sr := models.NewStepResult(models.Undefined, pickle.Id, step.Id, match, pickledAttachments, nil) s.storage.MustInsertPickleStepResult(sr) s.fmt.Undefined(pickle, step, match.GetInternalStepDefinition()) @@ -198,8 +274,10 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena } if scenarioErr != nil { - sr = models.NewStepResult(pickle.Id, step.Id, match) - sr.Status = models.Skipped + pickledAttachments := pickleAttachments(ctx) + ctx = clearAttach(ctx) + + sr := models.NewStepResult(models.Skipped, pickle.Id, step.Id, match, pickledAttachments, nil) s.storage.MustInsertPickleStepResult(sr) s.fmt.Skipped(pickle, step, match.GetInternalStepDefinition()) @@ -324,12 +402,16 @@ func (s *suite) runAfterScenarioHooks(ctx context.Context, pickle *messages.Pick } func (s *suite) maybeUndefined(ctx context.Context, text string, arg interface{}, stepType messages.PickleStepType) (context.Context, []string, error) { - step := s.matchStepTextAndType(text, stepType) + var undefined []string + step, err := s.matchStepTextAndType(text, stepType) + if err != nil { + return ctx, undefined, err + } + if nil == step { return ctx, []string{text}, nil } - var undefined []string if !step.Nested { return ctx, undefined, nil } @@ -372,10 +454,13 @@ func (s *suite) maybeSubSteps(ctx context.Context, result interface{}) (context. return ctx, fmt.Errorf("unexpected error, should have been godog.Steps: %T - %+v", result, result) } - var err error - for _, text := range steps { - if def := s.matchStepTextAndType(text, messages.PickleStepType_UNKNOWN); def == nil { + def, err := s.matchStepTextAndType(text, messages.PickleStepType_UNKNOWN) + if err != nil { + return ctx, err + } + + if def == nil { return ctx, ErrUndefined } else { ctx, err = s.runSubStep(ctx, text, def) @@ -419,7 +504,10 @@ func (s *suite) runSubStep(ctx context.Context, text string, def *models.StepDef return ctx, nil } -func (s *suite) matchStepTextAndType(text string, stepType messages.PickleStepType) *models.StepDefinition { +func (s *suite) matchStepTextAndType(text string, stepType messages.PickleStepType) (*models.StepDefinition, error) { + var first *models.StepDefinition + matchingExpressions := make([]string, 0) + for _, h := range s.steps { if m := h.Expr.FindStringSubmatch(text); len(m) > 0 { if !keywordMatches(h.Keyword, stepType) { @@ -430,9 +518,11 @@ func (s *suite) matchStepTextAndType(text string, stepType messages.PickleStepTy args = append(args, m) } + matchingExpressions = append(matchingExpressions, h.Expr.String()) + // since we need to assign arguments // better to copy the step definition - return &models.StepDefinition{ + match := &models.StepDefinition{ StepDefinition: formatters.StepDefinition{ Expr: h.Expr, Handler: h.Handler, @@ -442,9 +532,21 @@ func (s *suite) matchStepTextAndType(text string, stepType messages.PickleStepTy HandlerValue: h.HandlerValue, Nested: h.Nested, } + + if first == nil { + first = match + } + } + } + + if s.strict { + if len(matchingExpressions) > 1 { + errs := "\n " + strings.Join(matchingExpressions, "\n ") + return nil, fmt.Errorf("%w, step text: %s\n matches:%s", ErrAmbiguous, text, errs) } } - return nil + + return first, nil } func keywordMatches(k formatters.Keyword, stepType messages.PickleStepType) bool { @@ -481,11 +583,11 @@ func (s *suite) runSteps(ctx context.Context, pickle *Scenario, steps []*Step) ( } func (s *suite) shouldFail(err error) bool { - if err == nil || err == ErrSkip { + if err == nil || errors.Is(err, ErrSkip) { return false } - if err == ErrUndefined || err == ErrPending { + if errors.Is(err, ErrUndefined) || errors.Is(err, ErrPending) { return s.strict } @@ -518,10 +620,15 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) { s.fmt.Pickle(pickle) + dt := &testingT{ + name: pickle.Name, + } + ctx = setContextTestingT(ctx, dt) // scenario if s.testingT != nil { // Running scenario as a subtest. s.testingT.Run(pickle.Name, func(t *testing.T) { + dt.t = t ctx, err = s.runSteps(ctx, pickle, pickle.Steps) if s.shouldFail(err) { t.Errorf("%+v", err) diff --git a/backend/vendor/github.com/cucumber/godog/test_context.go b/backend/vendor/github.com/cucumber/godog/test_context.go index b1006415..8156c6d7 100644 --- a/backend/vendor/github.com/cucumber/godog/test_context.go +++ b/backend/vendor/github.com/cucumber/godog/test_context.go @@ -281,6 +281,7 @@ func (ctx ScenarioContext) Then(expr, stepFunc interface{}) { func (ctx ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface{}, keyword formatters.Keyword) { var regex *regexp.Regexp + // Validate the first input param is regex compatible switch t := expr.(type) { case *regexp.Regexp: regex = t @@ -289,45 +290,59 @@ func (ctx ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface{ case []byte: regex = regexp.MustCompile(string(t)) default: - panic(fmt.Sprintf("expecting expr to be a *regexp.Regexp or a string, got type: %T", expr)) + panic(fmt.Sprintf("expecting expr to be a *regexp.Regexp or a string or []byte, got type: %T", expr)) } - v := reflect.ValueOf(stepFunc) - typ := v.Type() - if typ.Kind() != reflect.Func { + // Validate that the handler is a function. + handlerType := reflect.TypeOf(stepFunc) + if handlerType.Kind() != reflect.Func { panic(fmt.Sprintf("expected handler to be func, but got: %T", stepFunc)) } - if typ.NumOut() > 2 { - panic(fmt.Sprintf("expected handler to return either zero, one or two values, but it has: %d", typ.NumOut())) + // FIXME = Validate the handler function param types here so + // that any errors are discovered early. + // StepDefinition.Run defines the supported types but fails at run time not registration time + + // Validate the function's return types. + helpPrefix := "expected handler to return one of error or context.Context or godog.Steps or (context.Context, error)" + isNested := false + + numOut := handlerType.NumOut() + switch numOut { + case 0: + // No return values. + case 1: + // One return value: should be error, Steps, or context.Context. + outType := handlerType.Out(0) + if outType == reflect.TypeOf(Steps{}) { + isNested = true + } else { + if outType != errorInterface && outType != contextInterface { + panic(fmt.Sprintf("%s, but got: %v", helpPrefix, outType)) + } + } + case 2: + // Two return values: should be (context.Context, error). + if handlerType.Out(0) != contextInterface || handlerType.Out(1) != errorInterface { + panic(fmt.Sprintf("%s, but got: %v, %v", helpPrefix, handlerType.Out(0), handlerType.Out(1))) + } + default: + // More than two return values. + panic(fmt.Sprintf("expected handler to return either zero, one or two values, but it has: %d", numOut)) } + // Register the handler def := &models.StepDefinition{ StepDefinition: formatters.StepDefinition{ Handler: stepFunc, Expr: regex, Keyword: keyword, }, - HandlerValue: v, - } - - if typ.NumOut() == 1 { - typ = typ.Out(0) - switch typ.Kind() { - case reflect.Interface: - if !typ.Implements(errorInterface) && !typ.Implements(contextInterface) { - panic(fmt.Sprintf("expected handler to return an error or context.Context, but got: %s", typ.Kind())) - } - case reflect.Slice: - if typ.Elem().Kind() != reflect.String { - panic(fmt.Sprintf("expected handler to return []string for multistep, but got: []%s", typ.Elem().Kind())) - } - def.Nested = true - default: - panic(fmt.Sprintf("expected handler to return an error or []string, but got: %s", typ.Kind())) - } + HandlerValue: reflect.ValueOf(stepFunc), + Nested: isNested, } + // stash the step ctx.suite.steps = append(ctx.suite.steps, def) } diff --git a/backend/vendor/github.com/cucumber/godog/testingt.go b/backend/vendor/github.com/cucumber/godog/testingt.go new file mode 100644 index 00000000..25981b89 --- /dev/null +++ b/backend/vendor/github.com/cucumber/godog/testingt.go @@ -0,0 +1,206 @@ +package godog + +import ( + "context" + "fmt" + "strings" + "testing" +) + +// T returns a TestingT compatible interface from the current test context. It will return nil if +// called outside the context of a test. This can be used with (for example) testify's assert and +// require packages. +func T(ctx context.Context) TestingT { + return getTestingT(ctx) +} + +// TestingT is a subset of the public methods implemented by go's testing.T. It allows assertion +// libraries to be used with godog, provided they depend only on this subset of methods. +type TestingT interface { + // Name returns the name of the current pickle under test + Name() string + // Log will log to the current testing.T log if set, otherwise it will log to stdout + Log(args ...interface{}) + // Logf will log a formatted string to the current testing.T log if set, otherwise it will log + // to stdout + Logf(format string, args ...interface{}) + // Error fails the current test and logs the provided arguments. Equivalent to calling Log then + // Fail. + Error(args ...interface{}) + // Errorf fails the current test and logs the formatted message. Equivalent to calling Logf then + // Fail. + Errorf(format string, args ...interface{}) + // Fail marks the current test as failed, but does not halt execution of the step. + Fail() + // FailNow marks the current test as failed and halts execution of the step. + FailNow() + // Fatal logs the provided arguments, marks the test as failed and halts execution of the step. + Fatal(args ...interface{}) + // Fatal logs the formatted message, marks the test as failed and halts execution of the step. + Fatalf(format string, args ...interface{}) + // Skip logs the provided arguments and marks the test as skipped but does not halt execution + // of the step. + Skip(args ...interface{}) + // Skipf logs the formatted message and marks the test as skipped but does not halt execution + // of the step. + Skipf(format string, args ...interface{}) + // SkipNow marks the current test as skipped and halts execution of the step. + SkipNow() + // Skipped returns true if the test has been marked as skipped. + Skipped() bool +} + +// Logf will log test output. If called in the context of a test and testing.T has been registered, +// this will log using the step's testing.T, else it will simply log to stdout. +func Logf(ctx context.Context, format string, args ...interface{}) { + if t := getTestingT(ctx); t != nil { + t.Logf(format, args...) + return + } + fmt.Printf(format+"\n", args...) +} + +// Log will log test output. If called in the context of a test and testing.T has been registered, +// this will log using the step's testing.T, else it will simply log to stdout. +func Log(ctx context.Context, args ...interface{}) { + if t := getTestingT(ctx); t != nil { + t.Log(args...) + return + } + fmt.Println(args...) +} + +// LoggedMessages returns an array of any logged messages that have been recorded during the test +// through calls to godog.Log / godog.Logf or via operations against godog.T(ctx) +func LoggedMessages(ctx context.Context) []string { + if t := getTestingT(ctx); t != nil { + return t.logMessages + } + return nil +} + +// errStopNow should be returned inside a panic within the test to immediately halt execution of that +// test +var errStopNow = fmt.Errorf("FailNow or SkipNow called") + +type testingT struct { + name string + t *testing.T + failed bool + skipped bool + failMessages []string + logMessages []string +} + +// check interface against our testingT and the upstream testing.B/F/T: +var ( + _ TestingT = &testingT{} + _ TestingT = (*testing.T)(nil) +) + +func (dt *testingT) Name() string { + if dt.t != nil { + return dt.t.Name() + } + return dt.name +} + +func (dt *testingT) Log(args ...interface{}) { + dt.logMessages = append(dt.logMessages, fmt.Sprint(args...)) + if dt.t != nil { + dt.t.Log(args...) + return + } + fmt.Println(args...) +} + +func (dt *testingT) Logf(format string, args ...interface{}) { + dt.logMessages = append(dt.logMessages, fmt.Sprintf(format, args...)) + if dt.t != nil { + dt.t.Logf(format, args...) + return + } + fmt.Printf(format+"\n", args...) +} + +func (dt *testingT) Error(args ...interface{}) { + dt.Log(args...) + dt.failMessages = append(dt.failMessages, fmt.Sprintln(args...)) + dt.Fail() +} + +func (dt *testingT) Errorf(format string, args ...interface{}) { + dt.Logf(format, args...) + dt.failMessages = append(dt.failMessages, fmt.Sprintf(format, args...)) + dt.Fail() +} + +func (dt *testingT) Fail() { + dt.failed = true +} + +func (dt *testingT) FailNow() { + dt.Fail() + panic(errStopNow) +} + +func (dt *testingT) Fatal(args ...interface{}) { + dt.Log(args...) + dt.FailNow() +} + +func (dt *testingT) Fatalf(format string, args ...interface{}) { + dt.Logf(format, args...) + dt.FailNow() +} + +func (dt *testingT) Skip(args ...interface{}) { + dt.Log(args...) + dt.skipped = true +} + +func (dt *testingT) Skipf(format string, args ...interface{}) { + dt.Logf(format, args...) + dt.skipped = true +} + +func (dt *testingT) SkipNow() { + dt.skipped = true + panic(errStopNow) +} + +func (dt *testingT) Skipped() bool { + return dt.skipped +} + +// isFailed will return an error representing the calls to Fail made during this test +func (dt *testingT) isFailed() error { + if dt.skipped { + return ErrSkip + } + if !dt.failed { + return nil + } + switch len(dt.failMessages) { + case 0: + return fmt.Errorf("fail called on TestingT") + case 1: + return fmt.Errorf(dt.failMessages[0]) + default: + return fmt.Errorf("checks failed:\n* %s", strings.Join(dt.failMessages, "\n* ")) + } +} + +type testingTCtxVal struct{} + +func setContextTestingT(ctx context.Context, dt *testingT) context.Context { + return context.WithValue(ctx, testingTCtxVal{}, dt) +} + +func getTestingT(ctx context.Context) *testingT { + dt, ok := ctx.Value(testingTCtxVal{}).(*testingT) + if !ok { + return nil + } + return dt +} diff --git a/backend/vendor/github.com/gofrs/uuid/README.md b/backend/vendor/github.com/gofrs/uuid/README.md index f5db14f0..4f73bec8 100644 --- a/backend/vendor/github.com/gofrs/uuid/README.md +++ b/backend/vendor/github.com/gofrs/uuid/README.md @@ -17,7 +17,7 @@ This package supports the following UUID versions: * Version 5, based on SHA-1 hashing of a named value (RFC-4122) This package also supports experimental Universally Unique Identifier implementations based on a -[draft RFC](https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03) that updates RFC-4122 +[draft RFC](https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html) that updates RFC-4122 * Version 6, a k-sortable id based on timestamp, and field-compatible with v1 (draft-peabody-dispatch-new-uuid-format, RFC-4122) * Version 7, a k-sortable id based on timestamp (draft-peabody-dispatch-new-uuid-format, RFC-4122) @@ -114,4 +114,4 @@ func main() { * [RFC-4122](https://tools.ietf.org/html/rfc4122) * [DCE 1.1: Authentication and Security Services](http://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01) -* [New UUID Formats RFC Draft (Peabody) Rev 03](https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03) +* [New UUID Formats RFC Draft (Peabody) Rev 04](https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html#) diff --git a/backend/vendor/github.com/gofrs/uuid/codec.go b/backend/vendor/github.com/gofrs/uuid/codec.go index e3014c68..66502641 100644 --- a/backend/vendor/github.com/gofrs/uuid/codec.go +++ b/backend/vendor/github.com/gofrs/uuid/codec.go @@ -22,8 +22,7 @@ package uuid import ( - "bytes" - "encoding/hex" + "errors" "fmt" ) @@ -45,11 +44,77 @@ func FromBytesOrNil(input []byte) UUID { return uuid } +var errInvalidFormat = errors.New("uuid: invalid UUID format") + +func fromHexChar(c byte) byte { + switch { + case '0' <= c && c <= '9': + return c - '0' + case 'a' <= c && c <= 'f': + return c - 'a' + 10 + case 'A' <= c && c <= 'F': + return c - 'A' + 10 + } + return 255 +} + +// Parse parses the UUID stored in the string text. Parsing and supported +// formats are the same as UnmarshalText. +func (u *UUID) Parse(s string) error { + switch len(s) { + case 32: // hash + case 36: // canonical + case 34, 38: + if s[0] != '{' || s[len(s)-1] != '}' { + return fmt.Errorf("uuid: incorrect UUID format in string %q", s) + } + s = s[1 : len(s)-1] + case 41, 45: + if s[:9] != "urn:uuid:" { + return fmt.Errorf("uuid: incorrect UUID format in string %q", s[:9]) + } + s = s[9:] + default: + return fmt.Errorf("uuid: incorrect UUID length %d in string %q", len(s), s) + } + // canonical + if len(s) == 36 { + if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { + return fmt.Errorf("uuid: incorrect UUID format in string %q", s) + } + for i, x := range [16]byte{ + 0, 2, 4, 6, + 9, 11, + 14, 16, + 19, 21, + 24, 26, 28, 30, 32, 34, + } { + v1 := fromHexChar(s[x]) + v2 := fromHexChar(s[x+1]) + if v1|v2 == 255 { + return errInvalidFormat + } + u[i] = (v1 << 4) | v2 + } + return nil + } + // hash like + for i := 0; i < 32; i += 2 { + v1 := fromHexChar(s[i]) + v2 := fromHexChar(s[i+1]) + if v1|v2 == 255 { + return errInvalidFormat + } + u[i/2] = (v1 << 4) | v2 + } + return nil +} + // FromString returns a UUID parsed from the input string. // Input is expected in a form accepted by UnmarshalText. -func FromString(input string) (UUID, error) { - u := UUID{} - err := u.UnmarshalText([]byte(input)) +func FromString(text string) (UUID, error) { + var u UUID + err := u.Parse(text) return u, err } @@ -66,133 +131,90 @@ func FromStringOrNil(input string) UUID { // MarshalText implements the encoding.TextMarshaler interface. // The encoding is the same as returned by the String() method. func (u UUID) MarshalText() ([]byte, error) { - return []byte(u.String()), nil + var buf [36]byte + encodeCanonical(buf[:], u) + return buf[:], nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. // Following formats are supported: // -// "6ba7b810-9dad-11d1-80b4-00c04fd430c8", -// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", -// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" -// "6ba7b8109dad11d180b400c04fd430c8" -// "{6ba7b8109dad11d180b400c04fd430c8}", -// "urn:uuid:6ba7b8109dad11d180b400c04fd430c8" +// "6ba7b810-9dad-11d1-80b4-00c04fd430c8", +// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", +// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" +// "6ba7b8109dad11d180b400c04fd430c8" +// "{6ba7b8109dad11d180b400c04fd430c8}", +// "urn:uuid:6ba7b8109dad11d180b400c04fd430c8" // // ABNF for supported UUID text representation follows: // -// URN := 'urn' -// UUID-NID := 'uuid' -// -// hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | -// 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | -// 'A' | 'B' | 'C' | 'D' | 'E' | 'F' +// URN := 'urn' +// UUID-NID := 'uuid' // -// hexoct := hexdig hexdig -// 2hexoct := hexoct hexoct -// 4hexoct := 2hexoct 2hexoct -// 6hexoct := 4hexoct 2hexoct -// 12hexoct := 6hexoct 6hexoct +// hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | +// 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | +// 'A' | 'B' | 'C' | 'D' | 'E' | 'F' // -// hashlike := 12hexoct -// canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct +// hexoct := hexdig hexdig +// 2hexoct := hexoct hexoct +// 4hexoct := 2hexoct 2hexoct +// 6hexoct := 4hexoct 2hexoct +// 12hexoct := 6hexoct 6hexoct // -// plain := canonical | hashlike -// uuid := canonical | hashlike | braced | urn +// hashlike := 12hexoct +// canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct // -// braced := '{' plain '}' | '{' hashlike '}' -// urn := URN ':' UUID-NID ':' plain +// plain := canonical | hashlike +// uuid := canonical | hashlike | braced | urn // -func (u *UUID) UnmarshalText(text []byte) error { - switch len(text) { - case 32: - return u.decodeHashLike(text) +// braced := '{' plain '}' | '{' hashlike '}' +// urn := URN ':' UUID-NID ':' plain +func (u *UUID) UnmarshalText(b []byte) error { + switch len(b) { + case 32: // hash + case 36: // canonical case 34, 38: - return u.decodeBraced(text) - case 36: - return u.decodeCanonical(text) + if b[0] != '{' || b[len(b)-1] != '}' { + return fmt.Errorf("uuid: incorrect UUID format in string %q", b) + } + b = b[1 : len(b)-1] case 41, 45: - return u.decodeURN(text) + if string(b[:9]) != "urn:uuid:" { + return fmt.Errorf("uuid: incorrect UUID format in string %q", b[:9]) + } + b = b[9:] default: - return fmt.Errorf("uuid: incorrect UUID length %d in string %q", len(text), text) - } -} - -// decodeCanonical decodes UUID strings that are formatted as defined in RFC-4122 (section 3): -// "6ba7b810-9dad-11d1-80b4-00c04fd430c8". -func (u *UUID) decodeCanonical(t []byte) error { - if t[8] != '-' || t[13] != '-' || t[18] != '-' || t[23] != '-' { - return fmt.Errorf("uuid: incorrect UUID format in string %q", t) + return fmt.Errorf("uuid: incorrect UUID length %d in string %q", len(b), b) } - - src := t - dst := u[:] - - for i, byteGroup := range byteGroups { - if i > 0 { - src = src[1:] // skip dash + if len(b) == 36 { + if b[8] != '-' || b[13] != '-' || b[18] != '-' || b[23] != '-' { + return fmt.Errorf("uuid: incorrect UUID format in string %q", b) } - _, err := hex.Decode(dst[:byteGroup/2], src[:byteGroup]) - if err != nil { - return err + for i, x := range [16]byte{ + 0, 2, 4, 6, + 9, 11, + 14, 16, + 19, 21, + 24, 26, 28, 30, 32, 34, + } { + v1 := fromHexChar(b[x]) + v2 := fromHexChar(b[x+1]) + if v1|v2 == 255 { + return errInvalidFormat + } + u[i] = (v1 << 4) | v2 } - src = src[byteGroup:] - dst = dst[byteGroup/2:] - } - - return nil -} - -// decodeHashLike decodes UUID strings that are using the following format: -// "6ba7b8109dad11d180b400c04fd430c8". -func (u *UUID) decodeHashLike(t []byte) error { - src := t[:] - dst := u[:] - - _, err := hex.Decode(dst, src) - return err -} - -// decodeBraced decodes UUID strings that are using the following formats: -// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}" -// "{6ba7b8109dad11d180b400c04fd430c8}". -func (u *UUID) decodeBraced(t []byte) error { - l := len(t) - - if t[0] != '{' || t[l-1] != '}' { - return fmt.Errorf("uuid: incorrect UUID format in string %q", t) + return nil } - - return u.decodePlain(t[1 : l-1]) -} - -// decodeURN decodes UUID strings that are using the following formats: -// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" -// "urn:uuid:6ba7b8109dad11d180b400c04fd430c8". -func (u *UUID) decodeURN(t []byte) error { - total := len(t) - - urnUUIDPrefix := t[:9] - - if !bytes.Equal(urnUUIDPrefix, urnPrefix) { - return fmt.Errorf("uuid: incorrect UUID format in string %q", t) - } - - return u.decodePlain(t[9:total]) -} - -// decodePlain decodes UUID strings that are using the following formats: -// "6ba7b810-9dad-11d1-80b4-00c04fd430c8" or in hash-like format -// "6ba7b8109dad11d180b400c04fd430c8". -func (u *UUID) decodePlain(t []byte) error { - switch len(t) { - case 32: - return u.decodeHashLike(t) - case 36: - return u.decodeCanonical(t) - default: - return fmt.Errorf("uuid: incorrect UUID length %d in string %q", len(t), t) + for i := 0; i < 32; i += 2 { + v1 := fromHexChar(b[i]) + v2 := fromHexChar(b[i+1]) + if v1|v2 == 255 { + return errInvalidFormat + } + u[i/2] = (v1 << 4) | v2 } + return nil } // MarshalBinary implements the encoding.BinaryMarshaler interface. diff --git a/backend/vendor/github.com/gofrs/uuid/fuzz.go b/backend/vendor/github.com/gofrs/uuid/fuzz.go index afaefbc8..ccf8d4ca 100644 --- a/backend/vendor/github.com/gofrs/uuid/fuzz.go +++ b/backend/vendor/github.com/gofrs/uuid/fuzz.go @@ -19,6 +19,7 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//go:build gofuzz // +build gofuzz package uuid @@ -27,15 +28,15 @@ package uuid // // To run: // -// $ go get github.com/dvyukov/go-fuzz/... -// $ cd $GOPATH/src/github.com/gofrs/uuid -// $ go-fuzz-build github.com/gofrs/uuid -// $ go-fuzz -bin=uuid-fuzz.zip -workdir=./testdata +// $ go get github.com/dvyukov/go-fuzz/... +// $ cd $GOPATH/src/github.com/gofrs/uuid +// $ go-fuzz-build github.com/gofrs/uuid +// $ go-fuzz -bin=uuid-fuzz.zip -workdir=./testdata // // If you make significant changes to FromString / UnmarshalText and add // new cases to fromStringTests (in codec_test.go), please run // -// $ go test -seed_fuzz_corpus +// $ go test -seed_fuzz_corpus // // to seed the corpus with the new interesting inputs, then run the fuzzer. func Fuzz(data []byte) int { diff --git a/backend/vendor/github.com/gofrs/uuid/generator.go b/backend/vendor/github.com/gofrs/uuid/generator.go index 4550bc6b..44be9e15 100644 --- a/backend/vendor/github.com/gofrs/uuid/generator.go +++ b/backend/vendor/github.com/gofrs/uuid/generator.go @@ -38,7 +38,8 @@ import ( // UUID epoch (October 15, 1582) and Unix epoch (January 1, 1970). const epochStart = 122192928000000000 -type epochFunc func() time.Time +// EpochFunc is the function type used to provide the current time. +type EpochFunc func() time.Time // HWAddrFunc is the function type used to provide hardware (MAC) addresses. type HWAddrFunc func() (net.HardwareAddr, error) @@ -80,9 +81,9 @@ func NewV6() (UUID, error) { } // NewV7 returns a k-sortable UUID based on the current millisecond precision -// UNIX epoch and 74 bits of pseudorandom data. +// UNIX epoch and 74 bits of pseudorandom data. It supports single-node batch generation (multiple UUIDs in the same timestamp) with a Monotonic Random counter. // -// This is implemented based on revision 03 of the Peabody UUID draft, and may +// This is implemented based on revision 04 of the Peabody UUID draft, and may // be subject to change pending further revisions. Until the final specification // revision is finished, changes required to implement updates to the spec will // not be considered a breaking change. They will happen as a minor version @@ -119,13 +120,16 @@ type Gen struct { rand io.Reader - epochFunc epochFunc + epochFunc EpochFunc hwAddrFunc HWAddrFunc lastTime uint64 clockSequence uint16 hardwareAddr [6]byte } +// GenOption is a function type that can be used to configure a Gen generator. +type GenOption func(*Gen) + // interface check -- build will fail if *Gen doesn't satisfy Generator var _ Generator = (*Gen)(nil) @@ -147,18 +151,82 @@ func NewGen() *Gen { // MAC address being used, you'll need to create a new generator using this // function. func NewGenWithHWAF(hwaf HWAddrFunc) *Gen { - return &Gen{ + return NewGenWithOptions(WithHWAddrFunc(hwaf)) +} + +// NewGenWithOptions returns a new instance of Gen with the options provided. +// Most people should use NewGen() or NewGenWithHWAF() instead. +// +// To customize the generator, you can pass in one or more GenOption functions. +// For example: +// +// gen := NewGenWithOptions( +// WithHWAddrFunc(myHWAddrFunc), +// WithEpochFunc(myEpochFunc), +// WithRandomReader(myRandomReader), +// ) +// +// NewGenWithOptions(WithHWAddrFunc(myHWAddrFunc)) is equivalent to calling +// NewGenWithHWAF(myHWAddrFunc) +// NewGenWithOptions() is equivalent to calling NewGen() +func NewGenWithOptions(opts ...GenOption) *Gen { + gen := &Gen{ epochFunc: time.Now, - hwAddrFunc: hwaf, + hwAddrFunc: defaultHWAddrFunc, rand: rand.Reader, } + + for _, opt := range opts { + opt(gen) + } + + return gen +} + +// WithHWAddrFunc is a GenOption that allows you to provide your own HWAddrFunc +// function. +// When this option is nil, the defaultHWAddrFunc is used. +func WithHWAddrFunc(hwaf HWAddrFunc) GenOption { + return func(gen *Gen) { + if hwaf == nil { + hwaf = defaultHWAddrFunc + } + + gen.hwAddrFunc = hwaf + } +} + +// WithEpochFunc is a GenOption that allows you to provide your own EpochFunc +// function. +// When this option is nil, time.Now is used. +func WithEpochFunc(epochf EpochFunc) GenOption { + return func(gen *Gen) { + if epochf == nil { + epochf = time.Now + } + + gen.epochFunc = epochf + } +} + +// WithRandomReader is a GenOption that allows you to provide your own random +// reader. +// When this option is nil, the default rand.Reader is used. +func WithRandomReader(reader io.Reader) GenOption { + return func(gen *Gen) { + if reader == nil { + reader = rand.Reader + } + + gen.rand = reader + } } // NewV1 returns a UUID based on the current timestamp and MAC address. func (g *Gen) NewV1() (UUID, error) { u := UUID{} - timeNow, clockSeq, err := g.getClockSequence() + timeNow, clockSeq, err := g.getClockSequence(false) if err != nil { return Nil, err } @@ -225,7 +293,7 @@ func (g *Gen) NewV6() (UUID, error) { return Nil, err } - timeNow, clockSeq, err := g.getClockSequence() + timeNow, clockSeq, err := g.getClockSequence(false) if err != nil { return Nil, err } @@ -241,8 +309,12 @@ func (g *Gen) NewV6() (UUID, error) { return u, nil } -// getClockSequence returns the epoch and clock sequence for V1 and V6 UUIDs. -func (g *Gen) getClockSequence() (uint64, uint16, error) { +// getClockSequence returns the epoch and clock sequence for V1,V6 and V7 UUIDs. +// +// When useUnixTSMs is false, it uses the Coordinated Universal Time (UTC) as a count of 100- +// +// nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar). +func (g *Gen) getClockSequence(useUnixTSMs bool) (uint64, uint16, error) { var err error g.clockSequenceOnce.Do(func() { buf := make([]byte, 2) @@ -258,7 +330,12 @@ func (g *Gen) getClockSequence() (uint64, uint16, error) { g.storageMutex.Lock() defer g.storageMutex.Unlock() - timeNow := g.getEpoch() + var timeNow uint64 + if useUnixTSMs { + timeNow = uint64(g.epochFunc().UnixMilli()) + } else { + timeNow = g.getEpoch() + } // Clock didn't change since last UUID generation. // Should increase clock sequence. if timeNow <= g.lastTime { @@ -272,28 +349,51 @@ func (g *Gen) getClockSequence() (uint64, uint16, error) { // NewV7 returns a k-sortable UUID based on the current millisecond precision // UNIX epoch and 74 bits of pseudorandom data. // -// This is implemented based on revision 03 of the Peabody UUID draft, and may +// This is implemented based on revision 04 of the Peabody UUID draft, and may // be subject to change pending further revisions. Until the final specification // revision is finished, changes required to implement updates to the spec will // not be considered a breaking change. They will happen as a minor version // releases until the spec is final. func (g *Gen) NewV7() (UUID, error) { var u UUID - - if _, err := io.ReadFull(g.rand, u[6:]); err != nil { + /* https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html#name-uuid-version-7 + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | unix_ts_ms | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | unix_ts_ms | ver | rand_a | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |var| rand_b | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | rand_b | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ + + ms, clockSeq, err := g.getClockSequence(true) + if err != nil { return Nil, err } - - tn := g.epochFunc() - ms := uint64(tn.Unix())*1e3 + uint64(tn.Nanosecond())/1e6 - u[0] = byte(ms >> 40) + //UUIDv7 features a 48 bit timestamp. First 32bit (4bytes) represents seconds since 1970, followed by 2 bytes for the ms granularity. + u[0] = byte(ms >> 40) //1-6 bytes: big-endian unsigned number of Unix epoch timestamp u[1] = byte(ms >> 32) u[2] = byte(ms >> 24) u[3] = byte(ms >> 16) u[4] = byte(ms >> 8) u[5] = byte(ms) + //support batching by using a monotonic pseudo-random sequence + //The 6th byte contains the version and partially rand_a data. + //We will lose the most significant bites from the clockSeq (with SetVersion), but it is ok, we need the least significant that contains the counter to ensure the monotonic property + binary.BigEndian.PutUint16(u[6:8], clockSeq) // set rand_a with clock seq which is random and monotonic + + //override first 4bits of u[6]. u.SetVersion(V7) + + //set rand_b 64bits of pseudo-random bits (first 2 will be overridden) + if _, err = io.ReadFull(g.rand, u[8:16]); err != nil { + return Nil, err + } + //override first 2 bits of byte[8] for the variant u.SetVariant(VariantRFC4122) return u, nil diff --git a/backend/vendor/github.com/gofrs/uuid/sql.go b/backend/vendor/github.com/gofrs/uuid/sql.go index 6f254a4f..01d5d884 100644 --- a/backend/vendor/github.com/gofrs/uuid/sql.go +++ b/backend/vendor/github.com/gofrs/uuid/sql.go @@ -22,12 +22,14 @@ package uuid import ( - "bytes" + "database/sql" "database/sql/driver" - "encoding/json" "fmt" ) +var _ driver.Valuer = UUID{} +var _ sql.Scanner = (*UUID)(nil) + // Value implements the driver.Valuer interface. func (u UUID) Value() (driver.Value, error) { return u.String(), nil @@ -49,7 +51,9 @@ func (u *UUID) Scan(src interface{}) error { return u.UnmarshalText(src) case string: - return u.UnmarshalText([]byte(src)) + uu, err := FromString(src) + *u = uu + return err } return fmt.Errorf("uuid: cannot convert %T to UUID", src) @@ -83,27 +87,30 @@ func (u *NullUUID) Scan(src interface{}) error { return u.UUID.Scan(src) } +var nullJSON = []byte("null") + // MarshalJSON marshals the NullUUID as null or the nested UUID func (u NullUUID) MarshalJSON() ([]byte, error) { if !u.Valid { - return json.Marshal(nil) + return nullJSON, nil } - - return json.Marshal(u.UUID) + var buf [38]byte + buf[0] = '"' + encodeCanonical(buf[1:37], u.UUID) + buf[37] = '"' + return buf[:], nil } // UnmarshalJSON unmarshals a NullUUID func (u *NullUUID) UnmarshalJSON(b []byte) error { - if bytes.Equal(b, []byte("null")) { + if string(b) == "null" { u.UUID, u.Valid = Nil, false return nil } - - if err := json.Unmarshal(b, &u.UUID); err != nil { - return err + if n := len(b); n >= 2 && b[0] == '"' { + b = b[1 : n-1] } - - u.Valid = true - - return nil + err := u.UUID.UnmarshalText(b) + u.Valid = (err == nil) + return err } diff --git a/backend/vendor/github.com/gofrs/uuid/uuid.go b/backend/vendor/github.com/gofrs/uuid/uuid.go index e747e541..5320fb53 100644 --- a/backend/vendor/github.com/gofrs/uuid/uuid.go +++ b/backend/vendor/github.com/gofrs/uuid/uuid.go @@ -44,8 +44,6 @@ import ( "encoding/binary" "encoding/hex" "fmt" - "io" - "strings" "time" ) @@ -133,12 +131,6 @@ func TimestampFromV6(u UUID) (Timestamp, error) { return Timestamp(uint64(low) + (uint64(mid) << 12) + (uint64(hi) << 28)), nil } -// String parse helpers. -var ( - urnPrefix = []byte("urn:uuid:") - byteGroups = []int{8, 4, 4, 4, 12} -) - // Nil is the nil UUID, as specified in RFC-4122, that has all 128 bits set to // zero. var Nil = UUID{} @@ -182,22 +174,33 @@ func (u UUID) Bytes() []byte { return u[:] } +// encodeCanonical encodes the canonical RFC-4122 form of UUID u into the +// first 36 bytes dst. +func encodeCanonical(dst []byte, u UUID) { + const hextable = "0123456789abcdef" + dst[8] = '-' + dst[13] = '-' + dst[18] = '-' + dst[23] = '-' + for i, x := range [16]byte{ + 0, 2, 4, 6, + 9, 11, + 14, 16, + 19, 21, + 24, 26, 28, 30, 32, 34, + } { + c := u[i] + dst[x] = hextable[c>>4] + dst[x+1] = hextable[c&0x0f] + } +} + // String returns a canonical RFC-4122 string representation of the UUID: // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. func (u UUID) String() string { - buf := make([]byte, 36) - - hex.Encode(buf[0:8], u[0:4]) - buf[8] = '-' - hex.Encode(buf[9:13], u[4:6]) - buf[13] = '-' - hex.Encode(buf[14:18], u[6:8]) - buf[18] = '-' - hex.Encode(buf[19:23], u[8:10]) - buf[23] = '-' - hex.Encode(buf[24:], u[10:]) - - return string(buf) + var buf [36]byte + encodeCanonical(buf[:], u) + return string(buf[:]) } // Format implements fmt.Formatter for UUID values. @@ -210,52 +213,41 @@ func (u UUID) String() string { // All other verbs not handled directly by the fmt package (like '%p') are unsupported and will return // "%!verb(uuid.UUID=value)" as recommended by the fmt package. func (u UUID) Format(f fmt.State, c rune) { + if c == 'v' && f.Flag('#') { + fmt.Fprintf(f, "%#v", [Size]byte(u)) + return + } switch c { case 'x', 'X': - s := hex.EncodeToString(u.Bytes()) + b := make([]byte, 32) + hex.Encode(b, u[:]) if c == 'X' { - s = strings.Map(toCapitalHexDigits, s) - } - _, _ = io.WriteString(f, s) - case 'v': - var s string - if f.Flag('#') { - s = fmt.Sprintf("%#v", [Size]byte(u)) - } else { - s = u.String() + toUpperHex(b) } - _, _ = io.WriteString(f, s) - case 's', 'S': - s := u.String() + _, _ = f.Write(b) + case 'v', 's', 'S': + b, _ := u.MarshalText() if c == 'S' { - s = strings.Map(toCapitalHexDigits, s) + toUpperHex(b) } - _, _ = io.WriteString(f, s) + _, _ = f.Write(b) case 'q': - _, _ = io.WriteString(f, `"`+u.String()+`"`) + b := make([]byte, 38) + b[0] = '"' + encodeCanonical(b[1:], u) + b[37] = '"' + _, _ = f.Write(b) default: // invalid/unsupported format verb fmt.Fprintf(f, "%%!%c(uuid.UUID=%s)", c, u.String()) } } -func toCapitalHexDigits(ch rune) rune { - // convert a-f hex digits to A-F - switch ch { - case 'a': - return 'A' - case 'b': - return 'B' - case 'c': - return 'C' - case 'd': - return 'D' - case 'e': - return 'E' - case 'f': - return 'F' - default: - return ch +func toUpperHex(b []byte) { + for i, c := range b { + if 'a' <= c && c <= 'f' { + b[i] = c - ('a' - 'A') + } } } @@ -283,7 +275,8 @@ func (u *UUID) SetVariant(v byte) { // Must is a helper that wraps a call to a function returning (UUID, error) // and panics if the error is non-nil. It is intended for use in variable // initializations such as -// var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000")) +// +// var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000")) func Must(u UUID, err error) UUID { if err != nil { panic(err) diff --git a/backend/vendor/github.com/hashicorp/go-memdb/CODEOWNERS b/backend/vendor/github.com/hashicorp/go-memdb/CODEOWNERS new file mode 100644 index 00000000..2cad39ac --- /dev/null +++ b/backend/vendor/github.com/hashicorp/go-memdb/CODEOWNERS @@ -0,0 +1,13 @@ +# Each line is a file pattern followed by one or more owners. +# More on CODEOWNERS files: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners + +# Default owner +* @hashicorp/team-ip-compliance @hashicorp/raft-force + +# Add override rules below. Each line is a file/folder pattern followed by one or more owners. +# Being an owner means those groups or individuals will be added as reviewers to PRs affecting +# those areas of the code. +# Examples: +# /docs/ @docs-team +# *.js @js-team +# *.go @go-team diff --git a/backend/vendor/github.com/hashicorp/go-memdb/LICENSE b/backend/vendor/github.com/hashicorp/go-memdb/LICENSE index e87a115e..f4f97ee5 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/LICENSE +++ b/backend/vendor/github.com/hashicorp/go-memdb/LICENSE @@ -1,3 +1,5 @@ +Copyright (c) 2015 HashiCorp, Inc. + Mozilla Public License, version 2.0 1. Definitions diff --git a/backend/vendor/github.com/hashicorp/go-memdb/changes.go b/backend/vendor/github.com/hashicorp/go-memdb/changes.go index 35089f5c..4761e925 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/changes.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/changes.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package memdb // Changes describes a set of mutations to memDB tables performed during a diff --git a/backend/vendor/github.com/hashicorp/go-memdb/filter.go b/backend/vendor/github.com/hashicorp/go-memdb/filter.go index 0071ab31..2e135216 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/filter.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/filter.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package memdb // FilterFunc is a function that takes the results of an iterator and returns diff --git a/backend/vendor/github.com/hashicorp/go-memdb/index.go b/backend/vendor/github.com/hashicorp/go-memdb/index.go index 172a0e86..588e1c89 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/index.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/index.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package memdb import ( diff --git a/backend/vendor/github.com/hashicorp/go-memdb/memdb.go b/backend/vendor/github.com/hashicorp/go-memdb/memdb.go index 0508d0aa..13cc6a8c 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/memdb.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/memdb.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + // Package memdb provides an in-memory database that supports transactions // and MVCC. package memdb diff --git a/backend/vendor/github.com/hashicorp/go-memdb/schema.go b/backend/vendor/github.com/hashicorp/go-memdb/schema.go index e6a9b526..2d66f996 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/schema.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/schema.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package memdb import "fmt" diff --git a/backend/vendor/github.com/hashicorp/go-memdb/txn.go b/backend/vendor/github.com/hashicorp/go-memdb/txn.go index 951c2a1d..f83f4fab 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/txn.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/txn.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package memdb import ( diff --git a/backend/vendor/github.com/hashicorp/go-memdb/watch.go b/backend/vendor/github.com/hashicorp/go-memdb/watch.go index 13a4da14..4d9cc7ee 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/watch.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/watch.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package memdb import ( diff --git a/backend/vendor/github.com/hashicorp/go-memdb/watch_few.go b/backend/vendor/github.com/hashicorp/go-memdb/watch_few.go index b211eeea..ccdbff0f 100644 --- a/backend/vendor/github.com/hashicorp/go-memdb/watch_few.go +++ b/backend/vendor/github.com/hashicorp/go-memdb/watch_few.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package memdb //go:generate sh -c "go run watch-gen/main.go >watch_few.go" diff --git a/backend/vendor/github.com/hashicorp/golang-lru/LICENSE b/backend/vendor/github.com/hashicorp/golang-lru/LICENSE index be2cc4df..0e5d580e 100644 --- a/backend/vendor/github.com/hashicorp/golang-lru/LICENSE +++ b/backend/vendor/github.com/hashicorp/golang-lru/LICENSE @@ -1,3 +1,5 @@ +Copyright (c) 2014 HashiCorp, Inc. + Mozilla Public License, version 2.0 1. Definitions diff --git a/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru.go b/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru.go index a86c8539..9233583c 100644 --- a/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru.go +++ b/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru.go @@ -25,7 +25,7 @@ type entry struct { // NewLRU constructs an LRU of the given size func NewLRU(size int, onEvict EvictCallback) (*LRU, error) { if size <= 0 { - return nil, errors.New("Must provide a positive size") + return nil, errors.New("must provide a positive size") } c := &LRU{ size: size, @@ -109,7 +109,7 @@ func (c *LRU) Remove(key interface{}) (present bool) { } // RemoveOldest removes the oldest item from the cache. -func (c *LRU) RemoveOldest() (key interface{}, value interface{}, ok bool) { +func (c *LRU) RemoveOldest() (key, value interface{}, ok bool) { ent := c.evictList.Back() if ent != nil { c.removeElement(ent) @@ -120,7 +120,7 @@ func (c *LRU) RemoveOldest() (key interface{}, value interface{}, ok bool) { } // GetOldest returns the oldest entry -func (c *LRU) GetOldest() (key interface{}, value interface{}, ok bool) { +func (c *LRU) GetOldest() (key, value interface{}, ok bool) { ent := c.evictList.Back() if ent != nil { kv := ent.Value.(*entry) diff --git a/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru_interface.go b/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru_interface.go index 92d70934..cb7f8caf 100644 --- a/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru_interface.go +++ b/backend/vendor/github.com/hashicorp/golang-lru/simplelru/lru_interface.go @@ -1,3 +1,4 @@ +// Package simplelru provides simple LRU implementation based on build-in container/list. package simplelru // LRUCache is the interface for simple LRU cache. @@ -34,6 +35,6 @@ type LRUCache interface { // Clears all cache entries. Purge() - // Resizes cache, returning number evicted - Resize(int) int + // Resizes cache, returning number evicted + Resize(int) int } diff --git a/backend/vendor/github.com/spf13/pflag/.editorconfig b/backend/vendor/github.com/spf13/pflag/.editorconfig new file mode 100644 index 00000000..4492e9f9 --- /dev/null +++ b/backend/vendor/github.com/spf13/pflag/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.go] +indent_style = tab diff --git a/backend/vendor/github.com/spf13/pflag/.golangci.yaml b/backend/vendor/github.com/spf13/pflag/.golangci.yaml new file mode 100644 index 00000000..b274f248 --- /dev/null +++ b/backend/vendor/github.com/spf13/pflag/.golangci.yaml @@ -0,0 +1,4 @@ +linters: + disable-all: true + enable: + - nolintlint diff --git a/backend/vendor/github.com/spf13/pflag/flag.go b/backend/vendor/github.com/spf13/pflag/flag.go index 24a5036e..7c058de3 100644 --- a/backend/vendor/github.com/spf13/pflag/flag.go +++ b/backend/vendor/github.com/spf13/pflag/flag.go @@ -160,7 +160,7 @@ type FlagSet struct { args []string // arguments after flags argsLenAtDash int // len(args) when a '--' was located when parsing, or -1 if no -- errorHandling ErrorHandling - output io.Writer // nil means stderr; use out() accessor + output io.Writer // nil means stderr; use Output() accessor interspersed bool // allow interspersed option/non-option args normalizeNameFunc func(f *FlagSet, name string) NormalizedName @@ -255,13 +255,20 @@ func (f *FlagSet) normalizeFlagName(name string) NormalizedName { return n(f, name) } -func (f *FlagSet) out() io.Writer { +// Output returns the destination for usage and error messages. os.Stderr is returned if +// output was not set or was set to nil. +func (f *FlagSet) Output() io.Writer { if f.output == nil { return os.Stderr } return f.output } +// Name returns the name of the flag set. +func (f *FlagSet) Name() string { + return f.name +} + // SetOutput sets the destination for usage and error messages. // If output is nil, os.Stderr is used. func (f *FlagSet) SetOutput(output io.Writer) { @@ -358,7 +365,7 @@ func (f *FlagSet) ShorthandLookup(name string) *Flag { } if len(name) > 1 { msg := fmt.Sprintf("can not look up shorthand which is more than one ASCII character: %q", name) - fmt.Fprintf(f.out(), msg) + fmt.Fprintf(f.Output(), msg) panic(msg) } c := name[0] @@ -482,7 +489,7 @@ func (f *FlagSet) Set(name, value string) error { } if flag.Deprecated != "" { - fmt.Fprintf(f.out(), "Flag --%s has been deprecated, %s\n", flag.Name, flag.Deprecated) + fmt.Fprintf(f.Output(), "Flag --%s has been deprecated, %s\n", flag.Name, flag.Deprecated) } return nil } @@ -523,7 +530,7 @@ func Set(name, value string) error { // otherwise, the default values of all defined flags in the set. func (f *FlagSet) PrintDefaults() { usages := f.FlagUsages() - fmt.Fprint(f.out(), usages) + fmt.Fprint(f.Output(), usages) } // defaultIsZeroValue returns true if the default value for this flag represents @@ -758,7 +765,7 @@ func PrintDefaults() { // defaultUsage is the default function to print a usage message. func defaultUsage(f *FlagSet) { - fmt.Fprintf(f.out(), "Usage of %s:\n", f.name) + fmt.Fprintf(f.Output(), "Usage of %s:\n", f.name) f.PrintDefaults() } @@ -844,7 +851,7 @@ func (f *FlagSet) AddFlag(flag *Flag) { _, alreadyThere := f.formal[normalizedFlagName] if alreadyThere { msg := fmt.Sprintf("%s flag redefined: %s", f.name, flag.Name) - fmt.Fprintln(f.out(), msg) + fmt.Fprintln(f.Output(), msg) panic(msg) // Happens only if flags are declared with identical names } if f.formal == nil { @@ -860,7 +867,7 @@ func (f *FlagSet) AddFlag(flag *Flag) { } if len(flag.Shorthand) > 1 { msg := fmt.Sprintf("%q shorthand is more than one ASCII character", flag.Shorthand) - fmt.Fprintf(f.out(), msg) + fmt.Fprintf(f.Output(), msg) panic(msg) } if f.shorthands == nil { @@ -870,7 +877,7 @@ func (f *FlagSet) AddFlag(flag *Flag) { used, alreadyThere := f.shorthands[c] if alreadyThere { msg := fmt.Sprintf("unable to redefine %q shorthand in %q flagset: it's already used for %q flag", c, f.name, used.Name) - fmt.Fprintf(f.out(), msg) + fmt.Fprintf(f.Output(), msg) panic(msg) } f.shorthands[c] = flag @@ -909,7 +916,7 @@ func VarP(value Value, name, shorthand, usage string) { func (f *FlagSet) failf(format string, a ...interface{}) error { err := fmt.Errorf(format, a...) if f.errorHandling != ContinueOnError { - fmt.Fprintln(f.out(), err) + fmt.Fprintln(f.Output(), err) f.usage() } return err @@ -1060,7 +1067,7 @@ func (f *FlagSet) parseSingleShortArg(shorthands string, args []string, fn parse } if flag.ShorthandDeprecated != "" { - fmt.Fprintf(f.out(), "Flag shorthand -%s has been deprecated, %s\n", flag.Shorthand, flag.ShorthandDeprecated) + fmt.Fprintf(f.Output(), "Flag shorthand -%s has been deprecated, %s\n", flag.Shorthand, flag.ShorthandDeprecated) } err = fn(flag, value) diff --git a/backend/vendor/github.com/spf13/pflag/ip.go b/backend/vendor/github.com/spf13/pflag/ip.go index 3d414ba6..06b8bcb5 100644 --- a/backend/vendor/github.com/spf13/pflag/ip.go +++ b/backend/vendor/github.com/spf13/pflag/ip.go @@ -16,6 +16,9 @@ func newIPValue(val net.IP, p *net.IP) *ipValue { func (i *ipValue) String() string { return net.IP(*i).String() } func (i *ipValue) Set(s string) error { + if s == "" { + return nil + } ip := net.ParseIP(strings.TrimSpace(s)) if ip == nil { return fmt.Errorf("failed to parse IP: %q", s) diff --git a/backend/vendor/github.com/spf13/pflag/ipnet_slice.go b/backend/vendor/github.com/spf13/pflag/ipnet_slice.go new file mode 100644 index 00000000..6b541aa8 --- /dev/null +++ b/backend/vendor/github.com/spf13/pflag/ipnet_slice.go @@ -0,0 +1,147 @@ +package pflag + +import ( + "fmt" + "io" + "net" + "strings" +) + +// -- ipNetSlice Value +type ipNetSliceValue struct { + value *[]net.IPNet + changed bool +} + +func newIPNetSliceValue(val []net.IPNet, p *[]net.IPNet) *ipNetSliceValue { + ipnsv := new(ipNetSliceValue) + ipnsv.value = p + *ipnsv.value = val + return ipnsv +} + +// Set converts, and assigns, the comma-separated IPNet argument string representation as the []net.IPNet value of this flag. +// If Set is called on a flag that already has a []net.IPNet assigned, the newly converted values will be appended. +func (s *ipNetSliceValue) Set(val string) error { + + // remove all quote characters + rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "") + + // read flag arguments with CSV parser + ipNetStrSlice, err := readAsCSV(rmQuote.Replace(val)) + if err != nil && err != io.EOF { + return err + } + + // parse ip values into slice + out := make([]net.IPNet, 0, len(ipNetStrSlice)) + for _, ipNetStr := range ipNetStrSlice { + _, n, err := net.ParseCIDR(strings.TrimSpace(ipNetStr)) + if err != nil { + return fmt.Errorf("invalid string being converted to CIDR: %s", ipNetStr) + } + out = append(out, *n) + } + + if !s.changed { + *s.value = out + } else { + *s.value = append(*s.value, out...) + } + + s.changed = true + + return nil +} + +// Type returns a string that uniquely represents this flag's type. +func (s *ipNetSliceValue) Type() string { + return "ipNetSlice" +} + +// String defines a "native" format for this net.IPNet slice flag value. +func (s *ipNetSliceValue) String() string { + + ipNetStrSlice := make([]string, len(*s.value)) + for i, n := range *s.value { + ipNetStrSlice[i] = n.String() + } + + out, _ := writeAsCSV(ipNetStrSlice) + return "[" + out + "]" +} + +func ipNetSliceConv(val string) (interface{}, error) { + val = strings.Trim(val, "[]") + // Emtpy string would cause a slice with one (empty) entry + if len(val) == 0 { + return []net.IPNet{}, nil + } + ss := strings.Split(val, ",") + out := make([]net.IPNet, len(ss)) + for i, sval := range ss { + _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) + if err != nil { + return nil, fmt.Errorf("invalid string being converted to CIDR: %s", sval) + } + out[i] = *n + } + return out, nil +} + +// GetIPNetSlice returns the []net.IPNet value of a flag with the given name +func (f *FlagSet) GetIPNetSlice(name string) ([]net.IPNet, error) { + val, err := f.getFlagType(name, "ipNetSlice", ipNetSliceConv) + if err != nil { + return []net.IPNet{}, err + } + return val.([]net.IPNet), nil +} + +// IPNetSliceVar defines a ipNetSlice flag with specified name, default value, and usage string. +// The argument p points to a []net.IPNet variable in which to store the value of the flag. +func (f *FlagSet) IPNetSliceVar(p *[]net.IPNet, name string, value []net.IPNet, usage string) { + f.VarP(newIPNetSliceValue(value, p), name, "", usage) +} + +// IPNetSliceVarP is like IPNetSliceVar, but accepts a shorthand letter that can be used after a single dash. +func (f *FlagSet) IPNetSliceVarP(p *[]net.IPNet, name, shorthand string, value []net.IPNet, usage string) { + f.VarP(newIPNetSliceValue(value, p), name, shorthand, usage) +} + +// IPNetSliceVar defines a []net.IPNet flag with specified name, default value, and usage string. +// The argument p points to a []net.IPNet variable in which to store the value of the flag. +func IPNetSliceVar(p *[]net.IPNet, name string, value []net.IPNet, usage string) { + CommandLine.VarP(newIPNetSliceValue(value, p), name, "", usage) +} + +// IPNetSliceVarP is like IPNetSliceVar, but accepts a shorthand letter that can be used after a single dash. +func IPNetSliceVarP(p *[]net.IPNet, name, shorthand string, value []net.IPNet, usage string) { + CommandLine.VarP(newIPNetSliceValue(value, p), name, shorthand, usage) +} + +// IPNetSlice defines a []net.IPNet flag with specified name, default value, and usage string. +// The return value is the address of a []net.IPNet variable that stores the value of that flag. +func (f *FlagSet) IPNetSlice(name string, value []net.IPNet, usage string) *[]net.IPNet { + p := []net.IPNet{} + f.IPNetSliceVarP(&p, name, "", value, usage) + return &p +} + +// IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash. +func (f *FlagSet) IPNetSliceP(name, shorthand string, value []net.IPNet, usage string) *[]net.IPNet { + p := []net.IPNet{} + f.IPNetSliceVarP(&p, name, shorthand, value, usage) + return &p +} + +// IPNetSlice defines a []net.IPNet flag with specified name, default value, and usage string. +// The return value is the address of a []net.IP variable that stores the value of the flag. +func IPNetSlice(name string, value []net.IPNet, usage string) *[]net.IPNet { + return CommandLine.IPNetSliceP(name, "", value, usage) +} + +// IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash. +func IPNetSliceP(name, shorthand string, value []net.IPNet, usage string) *[]net.IPNet { + return CommandLine.IPNetSliceP(name, shorthand, value, usage) +} diff --git a/backend/vendor/github.com/spf13/pflag/string_array.go b/backend/vendor/github.com/spf13/pflag/string_array.go index 4894af81..d1ff0a96 100644 --- a/backend/vendor/github.com/spf13/pflag/string_array.go +++ b/backend/vendor/github.com/spf13/pflag/string_array.go @@ -31,11 +31,7 @@ func (s *stringArrayValue) Append(val string) error { func (s *stringArrayValue) Replace(val []string) error { out := make([]string, len(val)) for i, d := range val { - var err error out[i] = d - if err != nil { - return err - } } *s.value = out return nil diff --git a/backend/vendor/github.com/valyala/fasthttp/coarseTime.go b/backend/vendor/github.com/valyala/fasthttp/coarsetime.go similarity index 100% rename from backend/vendor/github.com/valyala/fasthttp/coarseTime.go rename to backend/vendor/github.com/valyala/fasthttp/coarsetime.go diff --git a/backend/vendor/golang.org/x/oauth2/internal/doc.go b/backend/vendor/golang.org/x/oauth2/internal/doc.go index 03265e88..8c7c475f 100644 --- a/backend/vendor/golang.org/x/oauth2/internal/doc.go +++ b/backend/vendor/golang.org/x/oauth2/internal/doc.go @@ -2,5 +2,5 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package internal contains support packages for oauth2 package. +// Package internal contains support packages for [golang.org/x/oauth2]. package internal diff --git a/backend/vendor/golang.org/x/oauth2/internal/oauth2.go b/backend/vendor/golang.org/x/oauth2/internal/oauth2.go index 14989bea..71ea6ad1 100644 --- a/backend/vendor/golang.org/x/oauth2/internal/oauth2.go +++ b/backend/vendor/golang.org/x/oauth2/internal/oauth2.go @@ -13,7 +13,7 @@ import ( ) // ParseKey converts the binary contents of a private key file -// to an *rsa.PrivateKey. It detects whether the private key is in a +// to an [*rsa.PrivateKey]. It detects whether the private key is in a // PEM container or not. If so, it extracts the private key // from PEM container before conversion. It only supports PEM // containers with no passphrase. diff --git a/backend/vendor/golang.org/x/oauth2/internal/token.go b/backend/vendor/golang.org/x/oauth2/internal/token.go index e83ddeef..8389f246 100644 --- a/backend/vendor/golang.org/x/oauth2/internal/token.go +++ b/backend/vendor/golang.org/x/oauth2/internal/token.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math" "mime" "net/http" @@ -26,9 +25,9 @@ import ( // the requests to access protected resources on the OAuth 2.0 // provider's backend. // -// This type is a mirror of oauth2.Token and exists to break +// This type is a mirror of [golang.org/x/oauth2.Token] and exists to break // an otherwise-circular dependency. Other internal packages -// should convert this Token into an oauth2.Token before use. +// should convert this Token into an [golang.org/x/oauth2.Token] before use. type Token struct { // AccessToken is the token that authorizes and authenticates // the requests. @@ -50,9 +49,16 @@ type Token struct { // mechanisms for that TokenSource will not be used. Expiry time.Time + // ExpiresIn is the OAuth2 wire format "expires_in" field, + // which specifies how many seconds later the token expires, + // relative to an unknown time base approximately around "now". + // It is the application's responsibility to populate + // `Expiry` from `ExpiresIn` when required. + ExpiresIn int64 `json:"expires_in,omitempty"` + // Raw optionally contains extra metadata from the server // when updating a token. - Raw interface{} + Raw any } // tokenJSON is the struct representing the HTTP response from OAuth2 @@ -99,14 +105,6 @@ func (e *expirationTime) UnmarshalJSON(b []byte) error { return nil } -// RegisterBrokenAuthHeaderProvider previously did something. It is now a no-op. -// -// Deprecated: this function no longer does anything. Caller code that -// wants to avoid potential extra HTTP requests made during -// auto-probing of the provider's auth style should set -// Endpoint.AuthStyle. -func RegisterBrokenAuthHeaderProvider(tokenURL string) {} - // AuthStyle is a copy of the golang.org/x/oauth2 package's AuthStyle type. type AuthStyle int @@ -143,6 +141,11 @@ func (lc *LazyAuthStyleCache) Get() *AuthStyleCache { return c } +type authStyleCacheKey struct { + url string + clientID string +} + // AuthStyleCache is the set of tokenURLs we've successfully used via // RetrieveToken and which style auth we ended up using. // It's called a cache, but it doesn't (yet?) shrink. It's expected that @@ -150,26 +153,26 @@ func (lc *LazyAuthStyleCache) Get() *AuthStyleCache { // small. type AuthStyleCache struct { mu sync.Mutex - m map[string]AuthStyle // keyed by tokenURL + m map[authStyleCacheKey]AuthStyle } // lookupAuthStyle reports which auth style we last used with tokenURL // when calling RetrieveToken and whether we have ever done so. -func (c *AuthStyleCache) lookupAuthStyle(tokenURL string) (style AuthStyle, ok bool) { +func (c *AuthStyleCache) lookupAuthStyle(tokenURL, clientID string) (style AuthStyle, ok bool) { c.mu.Lock() defer c.mu.Unlock() - style, ok = c.m[tokenURL] + style, ok = c.m[authStyleCacheKey{tokenURL, clientID}] return } // setAuthStyle adds an entry to authStyleCache, documented above. -func (c *AuthStyleCache) setAuthStyle(tokenURL string, v AuthStyle) { +func (c *AuthStyleCache) setAuthStyle(tokenURL, clientID string, v AuthStyle) { c.mu.Lock() defer c.mu.Unlock() if c.m == nil { - c.m = make(map[string]AuthStyle) + c.m = make(map[authStyleCacheKey]AuthStyle) } - c.m[tokenURL] = v + c.m[authStyleCacheKey{tokenURL, clientID}] = v } // newTokenRequest returns a new *http.Request to retrieve a new token @@ -210,9 +213,9 @@ func cloneURLValues(v url.Values) url.Values { } func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string, v url.Values, authStyle AuthStyle, styleCache *AuthStyleCache) (*Token, error) { - needsAuthStyleProbe := authStyle == 0 + needsAuthStyleProbe := authStyle == AuthStyleUnknown if needsAuthStyleProbe { - if style, ok := styleCache.lookupAuthStyle(tokenURL); ok { + if style, ok := styleCache.lookupAuthStyle(tokenURL, clientID); ok { authStyle = style needsAuthStyleProbe = false } else { @@ -242,7 +245,7 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string, token, err = doTokenRoundTrip(ctx, req) } if needsAuthStyleProbe && err == nil { - styleCache.setAuthStyle(tokenURL, authStyle) + styleCache.setAuthStyle(tokenURL, clientID, authStyle) } // Don't overwrite `RefreshToken` with an empty value // if this was a token refreshing request. @@ -257,7 +260,7 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) { if err != nil { return nil, err } - body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1<<20)) + body, err := io.ReadAll(io.LimitReader(r.Body, 1<<20)) r.Body.Close() if err != nil { return nil, fmt.Errorf("oauth2: cannot fetch token: %v", err) @@ -312,7 +315,8 @@ func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) { TokenType: tj.TokenType, RefreshToken: tj.RefreshToken, Expiry: tj.expiry(), - Raw: make(map[string]interface{}), + ExpiresIn: int64(tj.ExpiresIn), + Raw: make(map[string]any), } json.Unmarshal(body, &token.Raw) // no error checks for optional fields } diff --git a/backend/vendor/golang.org/x/oauth2/internal/transport.go b/backend/vendor/golang.org/x/oauth2/internal/transport.go index b9db01dd..afc0aeb2 100644 --- a/backend/vendor/golang.org/x/oauth2/internal/transport.go +++ b/backend/vendor/golang.org/x/oauth2/internal/transport.go @@ -9,8 +9,8 @@ import ( "net/http" ) -// HTTPClient is the context key to use with golang.org/x/net/context's -// WithValue function to associate an *http.Client value with a context. +// HTTPClient is the context key to use with [context.WithValue] +// to associate an [*http.Client] value with a context. var HTTPClient ContextKey // ContextKey is just an empty struct. It exists so HTTPClient can be diff --git a/backend/vendor/golang.org/x/oauth2/oauth2.go b/backend/vendor/golang.org/x/oauth2/oauth2.go index eacdd7fd..3e3b6306 100644 --- a/backend/vendor/golang.org/x/oauth2/oauth2.go +++ b/backend/vendor/golang.org/x/oauth2/oauth2.go @@ -9,7 +9,6 @@ package oauth2 // import "golang.org/x/oauth2" import ( - "bytes" "context" "errors" "net/http" @@ -22,9 +21,9 @@ import ( ) // NoContext is the default context you should supply if not using -// your own context.Context (see https://golang.org/x/net/context). +// your own [context.Context]. // -// Deprecated: Use context.Background() or context.TODO() instead. +// Deprecated: Use [context.Background] or [context.TODO] instead. var NoContext = context.TODO() // RegisterBrokenAuthHeaderProvider previously did something. It is now a no-op. @@ -37,8 +36,8 @@ func RegisterBrokenAuthHeaderProvider(tokenURL string) {} // Config describes a typical 3-legged OAuth2 flow, with both the // client application information and the server's endpoint URLs. -// For the client credentials 2-legged OAuth2 flow, see the clientcredentials -// package (https://golang.org/x/oauth2/clientcredentials). +// For the client credentials 2-legged OAuth2 flow, see the +// [golang.org/x/oauth2/clientcredentials] package. type Config struct { // ClientID is the application's ID. ClientID string @@ -46,7 +45,7 @@ type Config struct { // ClientSecret is the application's secret. ClientSecret string - // Endpoint contains the resource server's token endpoint + // Endpoint contains the authorization server's token endpoint // URLs. These are constants specific to each server and are // often available via site-specific packages, such as // google.Endpoint or github.Endpoint. @@ -135,7 +134,7 @@ type setParam struct{ k, v string } func (p setParam) setValue(m url.Values) { m.Set(p.k, p.v) } -// SetAuthURLParam builds an AuthCodeOption which passes key/value parameters +// SetAuthURLParam builds an [AuthCodeOption] which passes key/value parameters // to a provider's authorization endpoint. func SetAuthURLParam(key, value string) AuthCodeOption { return setParam{key, value} @@ -148,8 +147,8 @@ func SetAuthURLParam(key, value string) AuthCodeOption { // request and callback. The authorization server includes this value when // redirecting the user agent back to the client. // -// Opts may include AccessTypeOnline or AccessTypeOffline, as well -// as ApprovalForce. +// Opts may include [AccessTypeOnline] or [AccessTypeOffline], as well +// as [ApprovalForce]. // // To protect against CSRF attacks, opts should include a PKCE challenge // (S256ChallengeOption). Not all servers support PKCE. An alternative is to @@ -158,7 +157,7 @@ func SetAuthURLParam(key, value string) AuthCodeOption { // PKCE), https://www.oauth.com/oauth2-servers/pkce/ and // https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-09.html#name-cross-site-request-forgery (describing both approaches) func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string { - var buf bytes.Buffer + var buf strings.Builder buf.WriteString(c.Endpoint.AuthURL) v := url.Values{ "response_type": {"code"}, @@ -194,7 +193,7 @@ func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string { // and when other authorization grant types are not available." // See https://tools.ietf.org/html/rfc6749#section-4.3 for more info. // -// The provided context optionally controls which HTTP client is used. See the HTTPClient variable. +// The provided context optionally controls which HTTP client is used. See the [HTTPClient] variable. func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error) { v := url.Values{ "grant_type": {"password"}, @@ -212,10 +211,10 @@ func (c *Config) PasswordCredentialsToken(ctx context.Context, username, passwor // It is used after a resource provider redirects the user back // to the Redirect URI (the URL obtained from AuthCodeURL). // -// The provided context optionally controls which HTTP client is used. See the HTTPClient variable. +// The provided context optionally controls which HTTP client is used. See the [HTTPClient] variable. // -// The code will be in the *http.Request.FormValue("code"). Before -// calling Exchange, be sure to validate FormValue("state") if you are +// The code will be in the [http.Request.FormValue]("code"). Before +// calling Exchange, be sure to validate [http.Request.FormValue]("state") if you are // using it to protect against CSRF attacks. // // If using PKCE to protect against CSRF attacks, opts should include a @@ -242,10 +241,10 @@ func (c *Config) Client(ctx context.Context, t *Token) *http.Client { return NewClient(ctx, c.TokenSource(ctx, t)) } -// TokenSource returns a TokenSource that returns t until t expires, +// TokenSource returns a [TokenSource] that returns t until t expires, // automatically refreshing it as necessary using the provided context. // -// Most users will use Config.Client instead. +// Most users will use [Config.Client] instead. func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource { tkr := &tokenRefresher{ ctx: ctx, @@ -260,7 +259,7 @@ func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource { } } -// tokenRefresher is a TokenSource that makes "grant_type"=="refresh_token" +// tokenRefresher is a TokenSource that makes "grant_type=refresh_token" // HTTP requests to renew a token using a RefreshToken. type tokenRefresher struct { ctx context.Context // used to get HTTP requests @@ -305,8 +304,7 @@ type reuseTokenSource struct { } // Token returns the current token if it's still valid, else will -// refresh the current token (using r.Context for HTTP client -// information) and return the new one. +// refresh the current token and return the new one. func (s *reuseTokenSource) Token() (*Token, error) { s.mu.Lock() defer s.mu.Unlock() @@ -322,7 +320,7 @@ func (s *reuseTokenSource) Token() (*Token, error) { return t, nil } -// StaticTokenSource returns a TokenSource that always returns the same token. +// StaticTokenSource returns a [TokenSource] that always returns the same token. // Because the provided token t is never refreshed, StaticTokenSource is only // useful for tokens that never expire. func StaticTokenSource(t *Token) TokenSource { @@ -338,16 +336,16 @@ func (s staticTokenSource) Token() (*Token, error) { return s.t, nil } -// HTTPClient is the context key to use with golang.org/x/net/context's -// WithValue function to associate an *http.Client value with a context. +// HTTPClient is the context key to use with [context.WithValue] +// to associate a [*http.Client] value with a context. var HTTPClient internal.ContextKey -// NewClient creates an *http.Client from a Context and TokenSource. +// NewClient creates an [*http.Client] from a [context.Context] and [TokenSource]. // The returned client is not valid beyond the lifetime of the context. // -// Note that if a custom *http.Client is provided via the Context it +// Note that if a custom [*http.Client] is provided via the [context.Context] it // is used only for token acquisition and is not used to configure the -// *http.Client returned from NewClient. +// [*http.Client] returned from NewClient. // // As a special case, if src is nil, a non-OAuth2 client is returned // using the provided context. This exists to support related OAuth2 @@ -368,7 +366,7 @@ func NewClient(ctx context.Context, src TokenSource) *http.Client { } } -// ReuseTokenSource returns a TokenSource which repeatedly returns the +// ReuseTokenSource returns a [TokenSource] which repeatedly returns the // same token as long as it's valid, starting with t. // When its cached token is invalid, a new token is obtained from src. // @@ -376,10 +374,10 @@ func NewClient(ctx context.Context, src TokenSource) *http.Client { // (such as a file on disk) between runs of a program, rather than // obtaining new tokens unnecessarily. // -// The initial token t may be nil, in which case the TokenSource is +// The initial token t may be nil, in which case the [TokenSource] is // wrapped in a caching version if it isn't one already. This also // means it's always safe to wrap ReuseTokenSource around any other -// TokenSource without adverse effects. +// [TokenSource] without adverse effects. func ReuseTokenSource(t *Token, src TokenSource) TokenSource { // Don't wrap a reuseTokenSource in itself. That would work, // but cause an unnecessary number of mutex operations. @@ -397,8 +395,8 @@ func ReuseTokenSource(t *Token, src TokenSource) TokenSource { } } -// ReuseTokenSourceWithExpiry returns a TokenSource that acts in the same manner as the -// TokenSource returned by ReuseTokenSource, except the expiry buffer is +// ReuseTokenSourceWithExpiry returns a [TokenSource] that acts in the same manner as the +// [TokenSource] returned by [ReuseTokenSource], except the expiry buffer is // configurable. The expiration time of a token is calculated as // t.Expiry.Add(-earlyExpiry). func ReuseTokenSourceWithExpiry(t *Token, src TokenSource, earlyExpiry time.Duration) TokenSource { diff --git a/backend/vendor/golang.org/x/oauth2/pkce.go b/backend/vendor/golang.org/x/oauth2/pkce.go index 6a95da97..cea8374d 100644 --- a/backend/vendor/golang.org/x/oauth2/pkce.go +++ b/backend/vendor/golang.org/x/oauth2/pkce.go @@ -1,6 +1,7 @@ // Copyright 2023 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. + package oauth2 import ( @@ -20,9 +21,9 @@ const ( // This follows recommendations in RFC 7636. // // A fresh verifier should be generated for each authorization. -// S256ChallengeOption(verifier) should then be passed to Config.AuthCodeURL -// (or Config.DeviceAuth) and VerifierOption(verifier) to Config.Exchange -// (or Config.DeviceAccessToken). +// The resulting verifier should be passed to [Config.AuthCodeURL] or [Config.DeviceAuth] +// with [S256ChallengeOption], and to [Config.Exchange] or [Config.DeviceAccessToken] +// with [VerifierOption]. func GenerateVerifier() string { // "RECOMMENDED that the output of a suitable random number generator be // used to create a 32-octet sequence. The octet sequence is then @@ -36,22 +37,22 @@ func GenerateVerifier() string { return base64.RawURLEncoding.EncodeToString(data) } -// VerifierOption returns a PKCE code verifier AuthCodeOption. It should be -// passed to Config.Exchange or Config.DeviceAccessToken only. +// VerifierOption returns a PKCE code verifier [AuthCodeOption]. It should only be +// passed to [Config.Exchange] or [Config.DeviceAccessToken]. func VerifierOption(verifier string) AuthCodeOption { return setParam{k: codeVerifierKey, v: verifier} } // S256ChallengeFromVerifier returns a PKCE code challenge derived from verifier with method S256. // -// Prefer to use S256ChallengeOption where possible. +// Prefer to use [S256ChallengeOption] where possible. func S256ChallengeFromVerifier(verifier string) string { sha := sha256.Sum256([]byte(verifier)) return base64.RawURLEncoding.EncodeToString(sha[:]) } // S256ChallengeOption derives a PKCE code challenge derived from verifier with -// method S256. It should be passed to Config.AuthCodeURL or Config.DeviceAuth +// method S256. It should be passed to [Config.AuthCodeURL] or [Config.DeviceAuth] // only. func S256ChallengeOption(verifier string) AuthCodeOption { return challengeOption{ diff --git a/backend/vendor/golang.org/x/oauth2/token.go b/backend/vendor/golang.org/x/oauth2/token.go index 8c31136c..239ec329 100644 --- a/backend/vendor/golang.org/x/oauth2/token.go +++ b/backend/vendor/golang.org/x/oauth2/token.go @@ -44,7 +44,7 @@ type Token struct { // Expiry is the optional expiration time of the access token. // - // If zero, TokenSource implementations will reuse the same + // If zero, [TokenSource] implementations will reuse the same // token forever and RefreshToken or equivalent // mechanisms for that TokenSource will not be used. Expiry time.Time `json:"expiry,omitempty"` @@ -58,7 +58,7 @@ type Token struct { // raw optionally contains extra metadata from the server // when updating a token. - raw interface{} + raw any // expiryDelta is used to calculate when a token is considered // expired, by subtracting from Expiry. If zero, defaultExpiryDelta @@ -86,16 +86,16 @@ func (t *Token) Type() string { // SetAuthHeader sets the Authorization header to r using the access // token in t. // -// This method is unnecessary when using Transport or an HTTP Client +// This method is unnecessary when using [Transport] or an HTTP Client // returned by this package. func (t *Token) SetAuthHeader(r *http.Request) { r.Header.Set("Authorization", t.Type()+" "+t.AccessToken) } -// WithExtra returns a new Token that's a clone of t, but using the +// WithExtra returns a new [Token] that's a clone of t, but using the // provided raw extra map. This is only intended for use by packages // implementing derivative OAuth2 flows. -func (t *Token) WithExtra(extra interface{}) *Token { +func (t *Token) WithExtra(extra any) *Token { t2 := new(Token) *t2 = *t t2.raw = extra @@ -105,8 +105,8 @@ func (t *Token) WithExtra(extra interface{}) *Token { // Extra returns an extra field. // Extra fields are key-value pairs returned by the server as a // part of the token retrieval response. -func (t *Token) Extra(key string) interface{} { - if raw, ok := t.raw.(map[string]interface{}); ok { +func (t *Token) Extra(key string) any { + if raw, ok := t.raw.(map[string]any); ok { return raw[key] } @@ -163,6 +163,7 @@ func tokenFromInternal(t *internal.Token) *Token { TokenType: t.TokenType, RefreshToken: t.RefreshToken, Expiry: t.Expiry, + ExpiresIn: t.ExpiresIn, raw: t.Raw, } } diff --git a/backend/vendor/golang.org/x/oauth2/transport.go b/backend/vendor/golang.org/x/oauth2/transport.go index 90657915..8bbebbac 100644 --- a/backend/vendor/golang.org/x/oauth2/transport.go +++ b/backend/vendor/golang.org/x/oauth2/transport.go @@ -11,12 +11,12 @@ import ( "sync" ) -// Transport is an http.RoundTripper that makes OAuth 2.0 HTTP requests, -// wrapping a base RoundTripper and adding an Authorization header -// with a token from the supplied Sources. +// Transport is an [http.RoundTripper] that makes OAuth 2.0 HTTP requests, +// wrapping a base [http.RoundTripper] and adding an Authorization header +// with a token from the supplied [TokenSource]. // // Transport is a low-level mechanism. Most code will use the -// higher-level Config.Client method instead. +// higher-level [Config.Client] method instead. type Transport struct { // Source supplies the token to add to outgoing requests' // Authorization headers. @@ -47,7 +47,7 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { return nil, err } - req2 := cloneRequest(req) // per RoundTripper contract + req2 := req.Clone(req.Context()) token.SetAuthHeader(req2) // req.Body is assumed to be closed by the base RoundTripper. @@ -73,17 +73,3 @@ func (t *Transport) base() http.RoundTripper { } return http.DefaultTransport } - -// cloneRequest returns a clone of the provided *http.Request. -// The clone is a shallow copy of the struct and its Header map. -func cloneRequest(r *http.Request) *http.Request { - // shallow copy of the struct - r2 := new(http.Request) - *r2 = *r - // deep copy of the Header - r2.Header = make(http.Header, len(r.Header)) - for k, s := range r.Header { - r2.Header[k] = append([]string(nil), s...) - } - return r2 -} diff --git a/backend/vendor/gorm.io/gorm/License b/backend/vendor/gorm.io/gorm/LICENSE similarity index 100% rename from backend/vendor/gorm.io/gorm/License rename to backend/vendor/gorm.io/gorm/LICENSE diff --git a/backend/vendor/modules.txt b/backend/vendor/modules.txt index 40f027ab..12300037 100644 --- a/backend/vendor/modules.txt +++ b/backend/vendor/modules.txt @@ -26,7 +26,7 @@ github.com/coreos/go-oidc/v3/oidc # github.com/cucumber/gherkin/go/v26 v26.2.0 ## explicit; go 1.19 github.com/cucumber/gherkin/go/v26 -# github.com/cucumber/godog v0.13.0 +# github.com/cucumber/godog v0.15.0 ## explicit; go 1.16 github.com/cucumber/godog github.com/cucumber/godog/colors @@ -123,7 +123,7 @@ github.com/gofiber/fiber/v2/utils # github.com/gofiber/swagger v1.1.1 ## explicit; go 1.18 github.com/gofiber/swagger -# github.com/gofrs/uuid v4.3.1+incompatible +# github.com/gofrs/uuid v4.4.0+incompatible ## explicit github.com/gofrs/uuid # github.com/golang-jwt/jwt/v4 v4.5.2 @@ -150,10 +150,10 @@ github.com/grpc-ecosystem/grpc-gateway/v2/utilities # github.com/hashicorp/go-immutable-radix v1.3.1 ## explicit github.com/hashicorp/go-immutable-radix -# github.com/hashicorp/go-memdb v1.3.4 +# github.com/hashicorp/go-memdb v1.3.5 ## explicit; go 1.13 github.com/hashicorp/go-memdb -# github.com/hashicorp/golang-lru v0.5.4 +# github.com/hashicorp/golang-lru v1.0.2 ## explicit; go 1.12 github.com/hashicorp/golang-lru/simplelru # github.com/heetch/confita v0.10.0 @@ -263,7 +263,7 @@ github.com/remyoudompheng/bigfft # github.com/rivo/uniseg v0.4.7 ## explicit; go 1.18 github.com/rivo/uniseg -# github.com/spf13/pflag v1.0.5 +# github.com/spf13/pflag v1.0.6 ## explicit; go 1.12 github.com/spf13/pflag # github.com/stretchr/testify v1.10.0 @@ -409,8 +409,8 @@ golang.org/x/net/idna golang.org/x/net/internal/httpcommon golang.org/x/net/internal/timeseries golang.org/x/net/trace -# golang.org/x/oauth2 v0.29.0 -## explicit; go 1.23.0 +# golang.org/x/oauth2 v0.32.0 +## explicit; go 1.24.0 golang.org/x/oauth2 golang.org/x/oauth2/internal # golang.org/x/sync v0.13.0