mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-29 08:57:18 +02:00
propagate changes back from encrypted backend (#2079)
This commit is contained in:
parent
8924b1a5fc
commit
6aa716bc95
2 changed files with 24 additions and 7 deletions
|
@ -102,7 +102,14 @@ func (e *encryptedBackend) Put(ctx context.Context, record *databroker.Record) e
|
|||
newRecord := proto.Clone(record).(*databroker.Record)
|
||||
newRecord.Data = encrypted
|
||||
|
||||
return e.underlying.Put(ctx, newRecord)
|
||||
if err = e.underlying.Put(ctx, newRecord); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
record.ModifiedAt = newRecord.ModifiedAt
|
||||
record.Version = newRecord.Version
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *encryptedBackend) Sync(ctx context.Context, version uint64) (RecordStream, error) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/cryptutil"
|
||||
|
@ -19,6 +20,8 @@ func TestEncryptedBackend(t *testing.T) {
|
|||
m := map[string]*anypb.Any{}
|
||||
backend := &mockBackend{
|
||||
put: func(ctx context.Context, record *databroker.Record) error {
|
||||
record.ModifiedAt = timestamppb.Now()
|
||||
record.Version++
|
||||
m[record.GetId()] = record.GetData()
|
||||
return nil
|
||||
},
|
||||
|
@ -30,6 +33,8 @@ func TestEncryptedBackend(t *testing.T) {
|
|||
return &databroker.Record{
|
||||
Id: id,
|
||||
Data: data,
|
||||
Version: 1,
|
||||
ModifiedAt: timestamppb.Now(),
|
||||
}, nil
|
||||
},
|
||||
getAll: func(ctx context.Context) ([]*databroker.Record, uint64, error) {
|
||||
|
@ -38,6 +43,8 @@ func TestEncryptedBackend(t *testing.T) {
|
|||
records = append(records, &databroker.Record{
|
||||
Id: id,
|
||||
Data: data,
|
||||
Version: 1,
|
||||
ModifiedAt: timestamppb.Now(),
|
||||
})
|
||||
}
|
||||
return records, 0, nil
|
||||
|
@ -51,17 +58,20 @@ func TestEncryptedBackend(t *testing.T) {
|
|||
|
||||
any, _ := anypb.New(wrapperspb.String("HELLO WORLD"))
|
||||
|
||||
err = e.Put(ctx, &databroker.Record{
|
||||
rec := &databroker.Record{
|
||||
Type: "",
|
||||
Id: "TEST-1",
|
||||
Data: any,
|
||||
})
|
||||
}
|
||||
err = e.Put(ctx, rec)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
if assert.NotNil(t, m["TEST-1"], "key should be set") {
|
||||
assert.NotEqual(t, any.TypeUrl, m["TEST-1"].TypeUrl, "encrypted data should be a bytes type")
|
||||
assert.NotEqual(t, any.Value, m["TEST-1"].Value, "value should be encrypted")
|
||||
assert.NotNil(t, rec.ModifiedAt)
|
||||
assert.NotZero(t, rec.Version)
|
||||
}
|
||||
|
||||
record, err := e.Get(ctx, "", "TEST-1")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue