databroker: add support for querying the databroker (#1443)

* databroker: add support for querying the databroker

* remove query method, use getall so encryption works

* add test

* return early
This commit is contained in:
Caleb Doxsey 2020-09-22 16:01:37 -06:00 committed by GitHub
parent fdec45fe04
commit 2364da14c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 534 additions and 118 deletions

View file

@ -2,11 +2,14 @@ package storage
import (
"context"
"testing"
"time"
"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 {
@ -16,6 +19,7 @@ type mockBackend struct {
list func(ctx context.Context, sinceVersion string) ([]*databroker.Record, error)
delete func(ctx context.Context, id string) error
clearDeleted func(ctx context.Context, cutoff time.Time)
query func(ctx context.Context, query string, offset, limit int) ([]*databroker.Record, int, error)
watch func(ctx context.Context) <-chan struct{}
}
@ -47,6 +51,20 @@ func (m *mockBackend) ClearDeleted(ctx context.Context, cutoff time.Time) {
m.clearDeleted(ctx, cutoff)
}
func (m *mockBackend) Query(ctx context.Context, query string, offset, limit int) ([]*databroker.Record, int, error) {
return m.query(ctx, query, offset, limit)
}
func (m *mockBackend) Watch(ctx context.Context) <-chan struct{} {
return m.watch(ctx)
}
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"))
}