Skip to content

Commit

Permalink
BREAKING CHANGE(encryption): add crypter func to WithCassetteCrypto* …
Browse files Browse the repository at this point in the history
…CassetteOption
  • Loading branch information
seborama committed Aug 17, 2022
1 parent d75092c commit a21dcc9
Show file tree
Hide file tree
Showing 29 changed files with 85 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ _testmain.go
*.test
*.prof
/coverage.out
/bin
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<img src="https://github.com/seborama/govcr/actions/workflows/codeql-analysis.yml/badge.svg?branch=master" alt="govcr">
</a>

<a href="https://pkg.go.dev/github.com/seborama/govcr/v8">
<a href="https://pkg.go.dev/github.com/seborama/govcr/v9">
<img src="https://img.shields.io/badge/godoc-reference-blue.svg" alt="govcr">
</a>

<a href="https://goreportcard.com/report/github.com/seborama/govcr/v8">
<img src="https://goreportcard.com/badge/github.com/seborama/govcr/v8" alt="govcr">
<a href="https://goreportcard.com/report/github.com/seborama/govcr/v9">
<img src="https://goreportcard.com/badge/github.com/seborama/govcr/v9" alt="govcr">
</a>
</p>

Expand Down Expand Up @@ -50,15 +50,15 @@ We use a "relaxed" request matcher because `example.com` injects an "`Age`" head
## Install

```bash
go get github.com/seborama/govcr/v8@latest
go get github.com/seborama/govcr/v9@latest
```

For all available releases, please check the [releases](https://github.com/seborama/govcr/releases) tab on github.

And your source code would use this import:

```go
import "github.com/seborama/govcr/v8"
import "github.com/seborama/govcr/v9"
```

For versions of **govcr** before v5 (which don't use go.mod), use a dependency manager to lock the version you wish to use (perhaps v4)!
Expand All @@ -84,7 +84,7 @@ go get gopkg.in/seborama/govcr.v4

**govcr** is a wrapper around the Go `http.Client`. It can record live HTTP traffic to files (called "**cassettes**") and later replay HTTP requests ("**tracks**") from them instead of live HTTP calls.

The code documentation can be found on [godoc](https://pkg.go.dev/github.com/seborama/govcr/v8).
The code documentation can be found on [godoc](https://pkg.go.dev/github.com/seborama/govcr/v9).

When using **govcr**'s `http.Client`, the request is matched against the **tracks** on the '**cassette**':

Expand Down Expand Up @@ -185,7 +185,7 @@ As a reminder, you should **never** use a nonce value more than once with the sa
The command is located in the `cmd/govcr` folder, to install it:

```bash
go install github.com/seborama/govcr/v8/cmd/govcr@latest
go install github.com/seborama/govcr/v9/cmd/govcr@latest
```

Example usage:
Expand Down Expand Up @@ -344,7 +344,9 @@ At time of creating a new VCR with **govcr**:
vcr := govcr.NewVCR(
govcr.WithCassette(
exampleCassetteName4,
govcr.WithCassetteCrypto("test-fixtures/TestExample4.unsafe.key"),
govcr.WithCassetteCrypto(
encryption.NewChaCha20Poly1305WithRandomNonceGenerator,
"test-fixtures/TestExample4.unsafe.key"),
),
)
```
Expand All @@ -355,7 +357,9 @@ Or, at time of loading a cassette from the `ControlPanel`:
// See TestExample4 in tests for fully working example.
err := vcr.LoadCassette(
exampleCassetteName4,
govcr.WithCassetteCrypto("test-fixtures/TestExample4.unsafe.key"),
govcr.WithCassetteCrypto(
encryption.NewChaCha20Poly1305WithRandomNonceGenerator,
"test-fixtures/TestExample4.unsafe.key"),
)
```

Expand All @@ -380,9 +384,9 @@ vcr := govcr.NewVCR(
govcr.WithCassette(
exampleCassetteName4,
govcr.WithCassetteCryptoCustomNonce(
encryption.NewChaCha20Poly1305,
"test-fixtures/TestExample4.unsafe.key",
nonceGenerator,
),
nonceGenerator),
),
)
```
Expand Down
11 changes: 6 additions & 5 deletions cassette/cassette.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/google/uuid"
"github.com/pkg/errors"

"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v8/compression"
cryptoerr "github.com/seborama/govcr/v8/encryption/errors"
govcrerr "github.com/seborama/govcr/v8/errors"
"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9/cassette/track"
"github.com/seborama/govcr/v9/compression"
cryptoerr "github.com/seborama/govcr/v9/encryption/errors"
govcrerr "github.com/seborama/govcr/v9/errors"
"github.com/seborama/govcr/v9/stats"
)

// Cassette contains a set of tracks.
Expand Down Expand Up @@ -296,6 +296,7 @@ func getEncryptionMarker(data []byte) string {
marker := ""
for i, b := range data[1:] {
if i > 255 {
// give up: we should have already met with the closing `$` a long time ago
break
}

Expand Down
6 changes: 3 additions & 3 deletions cassette/cassette_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v8/cassette"
"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v8/encryption"
"github.com/seborama/govcr/v9/cassette"
"github.com/seborama/govcr/v9/cassette/track"
"github.com/seborama/govcr/v9/encryption"
)

func Test_cassette_GzipFilter(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cassette/cassette_wb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9/stats"
)

func Test_cassette_NumberOfTracks_PanicsWhenNoCassette(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cassette/track/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9/cassette/track"
)

func TestRequest_Clone(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cassette/track/mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9/cassette/track"
)

func Test_Mutator_On(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cassette/track/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/pkg/errors"

trkerr "github.com/seborama/govcr/v8/cassette/track/errors"
trkerr "github.com/seborama/govcr/v9/cassette/track/errors"
)

// Track is a recording (HTTP Request + Response) in a cassette.
Expand Down
4 changes: 2 additions & 2 deletions cmd/govcr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/pkg/errors"

"github.com/seborama/govcr/v8/cassette"
"github.com/seborama/govcr/v8/encryption"
"github.com/seborama/govcr/v9/cassette"
"github.com/seborama/govcr/v9/encryption"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/pkg/errors"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v8"
"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9"
"github.com/seborama/govcr/v9/stats"
)

func TestConcurrencySafety(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions controlpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package govcr
import (
"net/http"

"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9/cassette/track"
"github.com/seborama/govcr/v9/stats"
)

// ControlPanel holds the parts of a VCR that can be interacted with.
Expand Down
2 changes: 1 addition & 1 deletion controlpanel_wb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9/cassette/track"
)

func TestControlPanel_SetRecordingMutators(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion encryption/.study/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"

cryptoerr "github.com/seborama/govcr/v8/encryption/errors"
cryptoerr "github.com/seborama/govcr/v9/encryption/errors"
)

// nolint: deadcode
Expand Down
2 changes: 1 addition & 1 deletion encryption/aesgcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/aes"
"crypto/cipher"

cryptoerr "github.com/seborama/govcr/v8/encryption/errors"
cryptoerr "github.com/seborama/govcr/v9/encryption/errors"
)

// NewAESGCMWithRandomNonceGenerator creates a new Cryptor initialised with an
Expand Down
2 changes: 1 addition & 1 deletion encryption/aesgcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v8/encryption"
"github.com/seborama/govcr/v9/encryption"
)

func TestCryptor_AESGCM(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion encryption/chacha20poly1305_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v8/encryption"
"github.com/seborama/govcr/v9/encryption"
)

func TestCryptor_ChaCha20Poly1305(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions examples/Example1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"
"testing"

"github.com/seborama/govcr/v8"
"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9"
"github.com/seborama/govcr/v9/stats"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/Example2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/seborama/govcr/v8"
"github.com/seborama/govcr/v9"
)

const exampleCassetteName2 = "temp-fixtures/TestExample2.cassette.json"
Expand Down
4 changes: 2 additions & 2 deletions examples/Example3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"

"github.com/google/uuid"
"github.com/seborama/govcr/v8"
"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9"
"github.com/seborama/govcr/v9/cassette/track"
"github.com/stretchr/testify/require"
)

Expand Down
11 changes: 7 additions & 4 deletions examples/Example4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"os"
"testing"

"github.com/seborama/govcr/v8"
"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9"
"github.com/seborama/govcr/v9/encryption"
"github.com/seborama/govcr/v9/stats"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -20,7 +21,9 @@ func TestExample4(t *testing.T) {
vcr := govcr.NewVCR(
govcr.WithCassette(
exampleCassetteName4,
govcr.WithCassetteCrypto("test-fixtures/TestExample4.unsafe.key"),
govcr.WithCassetteCrypto(
encryption.NewChaCha20Poly1305WithRandomNonceGenerator,
"test-fixtures/TestExample4.unsafe.key"),
),
govcr.WithRequestMatcher(govcr.NewMethodURLRequestMatcher()), // use a "relaxed" request matcher
)
Expand All @@ -43,7 +46,7 @@ func TestExample4(t *testing.T) {
vcr.EjectCassette()
err := vcr.LoadCassette(
exampleCassetteName4,
govcr.WithCassetteCrypto("test-fixtures/TestExample4.unsafe.key"),
govcr.WithCassetteCrypto(encryption.NewChaCha20Poly1305WithRandomNonceGenerator, "test-fixtures/TestExample4.unsafe.key"),
)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/seborama/govcr/v8
module github.com/seborama/govcr/v9

go 1.17

Expand Down
4 changes: 2 additions & 2 deletions govcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/seborama/govcr/v8"
"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9"
"github.com/seborama/govcr/v9/stats"
)

func TestNewVCR(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions govcr_wb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/stretchr/testify/suite"

"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v8/stats"
"github.com/seborama/govcr/v9/cassette/track"
"github.com/seborama/govcr/v9/stats"
)

type GoVCRWBTestSuite struct {
Expand Down
2 changes: 1 addition & 1 deletion matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"net/url"

"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9/cassette/track"
)

// RequestMatcherFunc is a function that performs request comparison.
Expand Down
4 changes: 2 additions & 2 deletions matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/stretchr/testify/assert"

"github.com/seborama/govcr/v8"
"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9"
"github.com/seborama/govcr/v9/cassette/track"
)

func Test_DefaultHeaderMatcher(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package govcr
import (
"net/http"

"github.com/seborama/govcr/v8/cassette"
"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9/cassette"
"github.com/seborama/govcr/v9/cassette/track"
)

// HTTPMode defines govcr's mode for HTTP requests.
Expand Down
4 changes: 2 additions & 2 deletions pcb_wb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v8/cassette"
"github.com/seborama/govcr/v8/cassette/track"
"github.com/seborama/govcr/v9/cassette"
"github.com/seborama/govcr/v9/cassette/track"
)

func TestPrintedCircuitBoard_trackMatches(t *testing.T) {
Expand Down
Loading

0 comments on commit a21dcc9

Please sign in to comment.