From d7897108ef310bfe85c6847e41376c020f3b7ddd Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 14:08:54 +1300 Subject: [PATCH 1/9] :page_facing_up: LICENSE: adds MIT license. Fixes #4. --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c1e9a31 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Matthew Hartstonge + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 0cf30f198d25ec90bb8e8c4bf4805d4053bf69a1 Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 16:02:13 +1300 Subject: [PATCH 2/9] :construction_worker: ci/cd: enables github actions. --- .github/workflows/ci-test.yml | 32 ++++++++++++++++++++++++ .golangci.yml | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/ci-test.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml new file mode 100644 index 0000000..2e97b0a --- /dev/null +++ b/.github/workflows/ci-test.yml @@ -0,0 +1,32 @@ +name: ci-test +on: [ push, pull_request ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v2.5.2 + with: + # version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest # optional + + test: + runs-on: ubuntu-latest + strategy: + matrix: + go: [ 1.15, 1.16, 1.17, tip ] + + steps: + - name: set up go@${{ matrix.go }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: go@${{ matrix.go }} build + run: go build -v ./... + + - name: go@${{ matrix.go }} test + run: go test -v ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..ba426e9 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,46 @@ +run: + timeout: 60s +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - dogsled + - errcheck + - gochecknoglobals + - gochecknoinits + - gocognit + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - revive + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - prealloc + - predeclared + - exportloopref + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace +issues: + exclude-rules: + - path: _test\.go + linters: + - errcheck + - funlen + - gocyclo + - gochecknoinits + - gochecknoglobals + - lll From 854ba63de6b6438ee956db86c8f32a03ada7cf1a Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 16:10:50 +1300 Subject: [PATCH 3/9] :rotating_light: pkce: fixes whitespace issues (wsl). --- pkce.go | 3 ++- validation_test.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkce.go b/pkce.go index 89461c3..fe783a8 100644 --- a/pkce.go +++ b/pkce.go @@ -131,7 +131,6 @@ func VerifyCodeVerifier(method Method, codeVerifier string, codeChallenge string // received "code_verifier" and comparing it with the previously associated // "code_challenge", after first transforming it according to the // "code_challenge_method" method specified by the client. - switch method { case Plain: // If the "code_challenge_method" from Section 4.3 was "plain", they are @@ -172,6 +171,7 @@ func (k *Key) SetChallengeMethod(method Method) error { } k.challengeMethod = method + return nil } @@ -191,6 +191,7 @@ func (k *Key) setCodeVerifierLength(n int) error { } k.codeVerifierLen = n + return nil } diff --git a/validation_test.go b/validation_test.go index 372287a..e1c7a37 100644 --- a/validation_test.go +++ b/validation_test.go @@ -9,6 +9,7 @@ func Test_validateVerifierLen(t *testing.T) { type args struct { n int } + tests := []struct { name string args args @@ -43,6 +44,7 @@ func Test_validateVerifierLen(t *testing.T) { wantErr: true, }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if err := validateVerifierLen(tt.args.n); (err != nil) != tt.wantErr { @@ -56,6 +58,7 @@ func Test_validVerifierChar(t *testing.T) { type args struct { c byte } + type validVerifierCharTest struct { name string args args From acd442939af75f3520020b189170b217a6325c66 Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 16:12:45 +1300 Subject: [PATCH 4/9] :rotating_light: validation: simplifies if-return (revive). --- validation.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/validation.go b/validation.go index ad9f8c7..dc00fed 100644 --- a/validation.go +++ b/validation.go @@ -7,11 +7,7 @@ func validateCodeVerifier(verifier []byte) error { return err } - if err := validateCodeVerifierCharacters(verifier); err != nil { - return err - } - - return nil + return validateCodeVerifierCharacters(verifier) } // validateVerifierLen ensures the length of the code verifier is within the From d790575bd3b91f2bbb0e01614cf7cdcce19b87dc Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 16:38:02 +1300 Subject: [PATCH 5/9] :rotating_light: errors: reduces line lengths (lll). --- errors.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/errors.go b/errors.go index 1127037..54a344a 100644 --- a/errors.go +++ b/errors.go @@ -18,9 +18,16 @@ var ( // ErrVerifierCharacters enforces character compliance with the unreserved // character set as specified in RFC 7636, 4.1. - ErrVerifierCharacters = errors.New("code verifier must only contain unreserved characters in the set {'" + unreserved + "'}") + ErrVerifierCharacters = fmt.Errorf( + "code verifier must only contain unreserved characters from the set: {'%s'}", + unreserved, + ) // ErrVerifierLength enforces compliance with the minimum and maximum // lengths as specified in RFC 7636, 4.1. - ErrVerifierLength = errors.New(fmt.Sprintf("code verifier must be between %d and %d characters long", verifierMinLen, verifierMaxLen)) + ErrVerifierLength = fmt.Errorf( + "code verifier must be between %d and %d characters long", + verifierMinLen, + verifierMaxLen, + ) ) From 94b91241b84634009116459a69ef52d4dbcea726 Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 16:39:52 +1300 Subject: [PATCH 6/9] :construction_worker: ci/cd: fixes `go-test`. removes go version `tip`. --- .github/workflows/ci-test.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 2e97b0a..64cd312 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -2,7 +2,7 @@ name: ci-test on: [ push, pull_request ] jobs: - lint: + golangci-lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -13,13 +13,15 @@ jobs: # version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: latest # optional - test: + go-test: runs-on: ubuntu-latest strategy: matrix: - go: [ 1.15, 1.16, 1.17, tip ] + go: [ 1.15, 1.16, 1.17 ] steps: + - uses: actions/checkout@v2 + - name: set up go@${{ matrix.go }} uses: actions/setup-go@v2 with: From 74b17322994450c71f5fd9e028417a00c3bf414a Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 16:51:14 +1300 Subject: [PATCH 7/9] :construction_worker: ci/cd: breaks out linting and testing into separate github workflows. --- .github/workflows/{ci-test.yml => go.yml} | 17 +++-------------- .github/workflows/golangci-lint.yml | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) rename .github/workflows/{ci-test.yml => go.yml} (50%) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/ci-test.yml b/.github/workflows/go.yml similarity index 50% rename from .github/workflows/ci-test.yml rename to .github/workflows/go.yml index 64cd312..0f93d93 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/go.yml @@ -1,23 +1,12 @@ -name: ci-test +name: go on: [ push, pull_request ] jobs: - golangci-lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2.5.2 - with: - # version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: latest # optional - - go-test: + go: runs-on: ubuntu-latest strategy: matrix: - go: [ 1.15, 1.16, 1.17 ] + go: [ 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 ] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..c2cec38 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,14 @@ +name: golangci-lint +on: [ push, pull_request ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v2.5.2 + with: + # version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest # optional From ff4a1c0858487765035c27967abb77385de6e70a Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 17:14:38 +1300 Subject: [PATCH 8/9] :memo: README: adds go reference, go report and github action build badges. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f60ca84..6f7e3db 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # pkce +[![Go Reference](https://pkg.go.dev/badge/github.com/matthewhartstonge/pkce.svg)](https://pkg.go.dev/github.com/matthewhartstonge/pkce) +[![Go Report Card](https://goreportcard.com/badge/github.com/matthewhartstonge/pkce)](https://goreportcard.com/report/github.com/matthewhartstonge/pkce) +[![Go Test](https://github.com/matthewhartstonge/pkce/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/matthewhartstonge/pkce/actions/workflows/go.yml) +[![golangci-lint](https://github.com/matthewhartstonge/pkce/actions/workflows/golangci-lint.yml/badge.svg?branch=main)](https://github.com/matthewhartstonge/pkce/actions/workflows/golangci-lint.yml) + `pkce` implements the client side of RFC 7636 "Proof Key for Code Exchange by OAuth Public Clients" (PKCE) to enable the generation of cryptographically secure and specification compliant code verifiers and code challenges. With :sparkles: no external dependencies :sparkles:. From 3dc3dd809b5a99ddb393c08e42e99c95090d6fb5 Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Tue, 25 Jan 2022 17:15:30 +1300 Subject: [PATCH 9/9] :ship: v0.1.1 - 2022-01-25 Added: - :memo: README: adds code verifier verification examples. - :page_facing_up: LICENSE: adds MIT license. Fixes #4. - :construction_worker: ci/cd: enables github actions. Fixes #3. - :memo: README: adds go reference, go report and github action build badges. Fixed: - :memo: README: fixes a couple of spelling misteaks. - :rotating_light: pkce: fixes whitespace issues (wsl). - :rotating_light: validation: simplifies if-return (revive). - :rotating_light: errors: reduces line lengths (lll). --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdb32f5..bf24bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [v0.1.1] - 2022-01-25 ### Added - :memo: README: adds code verifier verification examples. +- :page_facing_up: LICENSE: adds MIT license. Fixes #4. +- :construction_worker: ci/cd: enables github actions. Fixes #3. +- :memo: README: adds go reference, go report and github action build badges. ### Fixed - :memo: README: fixes a couple of spelling misteaks. +- :rotating_light: pkce: fixes whitespace issues (wsl). +- :rotating_light: validation: simplifies if-return (revive). +- :rotating_light: errors: reduces line lengths (lll). ## [v0.1.0] - 2022-01-25 ### Added @@ -18,5 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Verification for an incoming code verifier. - URL parameter key constants. -[Unreleased]: https://github.com/matthewhartstonge/pkce/compare/v0.1.0...HEAD +[Unreleased]: https://github.com/matthewhartstonge/pkce/compare/v0.1.1...HEAD +[v0.1.1]: https://github.com/matthewhartstonge/pkce/releases/tag/v0.1.1 [v0.1.0]: https://github.com/matthewhartstonge/pkce/releases/tag/v0.1.0