Skip to content

Commit

Permalink
overhaul jwt v2 and v1 inter-tangling (#195)
Browse files Browse the repository at this point in the history
Move all the top-level go code into v2/v1compat and explicitly refer to that,
and with all other go.??? files removed, so that from the go module handling
perspective, this is all in one Go module.  This will prevent v1 code
references from going out to Go modules and fetching old vulnerable code.

We would use v2/internal/v1compat but we want this compatibility code to be
visible to tests in other software, such as nats-io/nats-account-server too.

This PR changes modules, imports, and CI test invocations, but makes no changes
to the Go functionality of the library.
  • Loading branch information
philpennock committed Mar 16, 2023
1 parent 8d1c62f commit e3e39d6
Show file tree
Hide file tree
Showing 39 changed files with 28 additions and 69 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- name: Lint
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
cd v2
GO_LIST=$(go list ./...)
go build
$(exit $(go fmt $GO_LIST | wc -l))
Expand All @@ -54,27 +55,31 @@ jobs:
run: |
set -e
mkdir -p cov
go get -t ./...
go test -v -race -covermode=atomic -coverprofile=./cov/v1.out -coverpkg=github.com/nats-io/jwt .
cd v2
go test -modfile=go_test.mod -v -race -covermode=atomic -coverprofile=../cov/v2.out -coverpkg=github.com/nats-io/jwt/v2 .
cd ..
gocovmerge ./cov/*.out > coverage.out
go get -t ./...
go test -v -race -covermode=atomic -coverprofile=../cov/v2.out -coverpkg=github.com/nats-io/jwt/v2 .
cd v1compat
go test -v -race -covermode=atomic -coverprofile=../../cov/v1.out -coverpkg=github.com/nats-io/jwt/v2/v1compat .
cd ../..
gocovmerge ./cov/*.out > ./coverage.out
set +e
if: matrix.canonical

- name: Tests (Windows)
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
set -e
cd v2
go get -t ./...
go test -v -race .
go test -modfile=v2/go_test.mod -v -race .
set +e
if: runner.os == 'Windows'

- name: Coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
# this needs to be where it can find a go.mod
working-directory: ./v2
# this path-to-profile is relative to the working-directory
path-to-profile: ../coverage.out
if: matrix.canonical
12 changes: 0 additions & 12 deletions go.mod

This file was deleted.

13 changes: 0 additions & 13 deletions go.sum

This file was deleted.

8 changes: 3 additions & 5 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module github.com/nats-io/jwt/v2

go 1.18

require (
github.com/nats-io/nkeys v0.3.1-0.20221205184623-5d8a6730c42c
)
require github.com/nats-io/nkeys v0.4.4

require (
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
)
12 changes: 6 additions & 6 deletions v2/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/nats-io/nkeys v0.3.1-0.20221205184623-5d8a6730c42c h1:3/I6jrE5AT258Nl8IZCu/9oGIfIsV/GL8aKQR8+Lpq4=
github.com/nats-io/nkeys v0.3.1-0.20221205184623-5d8a6730c42c/go.mod h1:JOEZlxMfMnmaLwr+mpmP+RGIYSxLNBFsZykCGaI2PvA=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA=
github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15 changes: 0 additions & 15 deletions v2/go_test.mod

This file was deleted.

6 changes: 0 additions & 6 deletions v2/go_test.sum

This file was deleted.

5 changes: 3 additions & 2 deletions v2/test/decoder_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
"testing"
"time"

v1jwt "github.com/nats-io/jwt"
. "github.com/nats-io/jwt/v2"
"github.com/nats-io/nkeys"

. "github.com/nats-io/jwt/v2"
v1jwt "github.com/nats-io/jwt/v2/v1compat"
)

func createExport(sub string) *v1jwt.Export {
Expand Down
2 changes: 1 addition & 1 deletion v2/test/genericclaims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"testing"
"time"

jwtv1 "github.com/nats-io/jwt"
. "github.com/nats-io/jwt/v2"
jwtv1 "github.com/nats-io/jwt/v2/v1compat"
)

func TestNewGenericClaims(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion v2/test/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"strings"
"testing"

. "github.com/nats-io/jwt/v2"
"github.com/nats-io/nkeys"

. "github.com/nats-io/jwt/v2"
)

func Trace(message string) string {
Expand Down
2 changes: 1 addition & 1 deletion Makefile → v2/v1compat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build:
go build

test:
./scripts/test.sh
../../../scripts/test.sh

fmt:
gofmt -w -s *.go
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e3e39d6

Please sign in to comment.