Skip to content

Commit 7d89605

Browse files
committed
all: stop depending on tink-go's testutil
This is a follow-up to #150, because we missed a couple additional uses. Move the forked dependency to an internal package re-export the type name, and update all the usages.
1 parent 328fa8f commit 7d89605

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

cmd/setec/setec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/creachadair/flax"
3030
"github.com/tailscale/setec/audit"
3131
"github.com/tailscale/setec/client/setec"
32+
"github.com/tailscale/setec/internal/tinktestutil"
3233
"github.com/tailscale/setec/server"
3334
"github.com/tailscale/setec/types/api"
3435
"github.com/tink-crypto/tink-go-awskms/v2/integration/awskms"
@@ -188,7 +189,7 @@ func runServer(env *command.Env) error {
188189
serverArgs.Hostname = "setec-dev"
189190
}
190191
if serverArgs.KMSKeyName == "" {
191-
kek = &dummyAEAD{
192+
kek = &tinktestutil.DummyAEAD{
192193
Name: "SetecDevOnlyDummyEncryption",
193194
}
194195
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
//
1515
////////////////////////////////////////////////////////////////////////////////
1616

17-
// This file is a copy of tink-go's https://github.com/tink-crypto/tink-go/blob/v2.1.0/testutil/testutil.go#L90-L130
18-
// with its type name unexported.
17+
// This file a copy of tink-go's https://github.com/tink-crypto/tink-go/blob/v2.1.0/testutil/testutil.go#L90-L130
1918
//
2019
// We do this to avoid https://github.com/tink-crypto/tink-go/issues/31 happening
2120
// in tink-go's testutil init function, which breaks our assumptions in CI
2221
// that things don't hit the network.
2322

24-
package main
23+
package tinktestutil
2524

2625
import (
2726
"bytes"
@@ -30,11 +29,11 @@ import (
3029
"fmt"
3130
)
3231

33-
// dummyAEAD is a dummy implementation of AEAD interface. It "encrypts" data
32+
// DummyAEAD is a dummy implementation of AEAD interface. It "encrypts" data
3433
// with a simple serialization capturing the dummy name, plaintext, and
3534
// associated data, and "decrypts" it by reversing this and checking that the
3635
// name and associated data match.
37-
type dummyAEAD struct {
36+
type DummyAEAD struct {
3837
Name string
3938
}
4039

@@ -45,7 +44,7 @@ type dummyAEADData struct {
4544
}
4645

4746
// Encrypt encrypts the plaintext.
48-
func (a *dummyAEAD) Encrypt(plaintext []byte, associatedData []byte) ([]byte, error) {
47+
func (a *DummyAEAD) Encrypt(plaintext []byte, associatedData []byte) ([]byte, error) {
4948
buf := new(bytes.Buffer)
5049
encoder := gob.NewEncoder(buf)
5150
err := encoder.Encode(dummyAEADData{
@@ -60,7 +59,7 @@ func (a *dummyAEAD) Encrypt(plaintext []byte, associatedData []byte) ([]byte, er
6059
}
6160

6261
// Decrypt decrypts the ciphertext.
63-
func (a *dummyAEAD) Decrypt(ciphertext []byte, associatedData []byte) ([]byte, error) {
62+
func (a *DummyAEAD) Decrypt(ciphertext []byte, associatedData []byte) ([]byte, error) {
6463
data := dummyAEADData{}
6564
decoder := gob.NewDecoder(bytes.NewBuffer(ciphertext))
6665
if err := decoder.Decode(&data); err != nil {

server/server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717
"github.com/tailscale/setec/audit"
1818
"github.com/tailscale/setec/client/setec"
1919
"github.com/tailscale/setec/db"
20+
"github.com/tailscale/setec/internal/tinktestutil"
2021
"github.com/tailscale/setec/server"
2122
"github.com/tailscale/setec/setectest"
2223
"github.com/tailscale/setec/types/api"
23-
"github.com/tink-crypto/tink-go/v2/testutil"
2424
"tailscale.com/client/tailscale/apitype"
2525
"tailscale.com/tailcfg"
2626
)
@@ -37,7 +37,7 @@ func TestNew(t *testing.T) {
3737
path := filepath.Join(t.TempDir(), "test.db")
3838
_, err := server.New(ctx, server.Config{
3939
DBPath: path,
40-
Key: &testutil.DummyAEAD{Name: t.Name()},
40+
Key: &tinktestutil.DummyAEAD{Name: t.Name()},
4141
AuditLog: audit.New(io.Discard),
4242
Mux: http.NewServeMux(),
4343
})
@@ -47,7 +47,7 @@ func TestNew(t *testing.T) {
4747
})
4848
t.Run("DB", func(t *testing.T) {
4949
path := filepath.Join(t.TempDir(), "test.db")
50-
kdb, err := db.Open(path, &testutil.DummyAEAD{Name: t.Name()}, audit.New(io.Discard))
50+
kdb, err := db.Open(path, &tinktestutil.DummyAEAD{Name: t.Name()}, audit.New(io.Discard))
5151
if err != nil {
5252
t.Fatalf("Open database: %v", err)
5353
}

setectest/dbtest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"github.com/tailscale/setec/acl"
1313
"github.com/tailscale/setec/audit"
1414
"github.com/tailscale/setec/db"
15+
"github.com/tailscale/setec/internal/tinktestutil"
1516
"github.com/tailscale/setec/types/api"
16-
"github.com/tink-crypto/tink-go/v2/testutil"
1717
"github.com/tink-crypto/tink-go/v2/tink"
1818
)
1919

@@ -71,7 +71,7 @@ func NewDB(t *testing.T, opts *DBOptions) *DB {
7171
t.Helper()
7272

7373
path := filepath.Join(t.TempDir(), "test.db")
74-
key := &testutil.DummyAEAD{Name: "setectest.DB." + t.Name()}
74+
key := &tinktestutil.DummyAEAD{Name: "setectest.DB." + t.Name()}
7575
adb, err := db.Open(path, key, opts.auditWriter())
7676
if err != nil {
7777
t.Fatalf("Creating test DB: %v", err)

0 commit comments

Comments
 (0)