mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-10 15:47:36 +02:00
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:
parent
fdec45fe04
commit
2364da14c8
8 changed files with 534 additions and 118 deletions
|
@ -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"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue