mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-30 10:56:28 +02:00
* refactor backend, implement encrypted store * refactor in-memory store * wip * wip * wip * add syncer test * fix redis expiry * fix linting issues * fix test by skipping non-config records * fix backoff import * fix init issues * fix query * wait for initial sync before starting directory sync * add type to SyncLatest * add more log messages, fix deadlock in in-memory store, always return server version from SyncLatest * update sync types and tests * add redis tests * skip macos in github actions * add comments to proto * split getBackend into separate methods * handle errors in initVersion * return different error for not found vs other errors in get * use exponential backoff for redis transaction retry * rename raw to result * use context instead of close channel * store type urls as constants in databroker * use timestampb instead of ptypes * fix group merging not waiting * change locked names * update GetAll to return latest record version * add method to grpcutil to get the type url for a protobuf type
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/protobuf/types/known/anypb"
|
|
|
|
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
|
"github.com/pomerium/pomerium/pkg/grpc/user"
|
|
)
|
|
|
|
type mockBackend struct {
|
|
put func(ctx context.Context, record *databroker.Record) error
|
|
get func(ctx context.Context, recordType, id string) (*databroker.Record, error)
|
|
getAll func(ctx context.Context) ([]*databroker.Record, uint64, error)
|
|
}
|
|
|
|
func (m *mockBackend) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockBackend) Put(ctx context.Context, record *databroker.Record) error {
|
|
return m.put(ctx, record)
|
|
}
|
|
|
|
func (m *mockBackend) Get(ctx context.Context, recordType, id string) (*databroker.Record, error) {
|
|
return m.get(ctx, recordType, id)
|
|
}
|
|
|
|
func (m *mockBackend) GetAll(ctx context.Context) ([]*databroker.Record, uint64, error) {
|
|
return m.getAll(ctx)
|
|
}
|
|
|
|
func (m *mockBackend) Sync(ctx context.Context, version uint64) (RecordStream, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func TestMatchAny(t *testing.T) {
|
|
u := &user.User{Id: "id", Name: "name", Email: "email"}
|
|
data, _ := anypb.New(u)
|
|
assert.True(t, MatchAny(data, ""))
|
|
assert.True(t, MatchAny(data, "id"))
|
|
assert.True(t, MatchAny(data, "name"))
|
|
assert.True(t, MatchAny(data, "email"))
|
|
assert.False(t, MatchAny(data, "nope"))
|
|
}
|