mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
add server test case
This commit is contained in:
parent
089de47139
commit
4a7527e980
2 changed files with 62 additions and 0 deletions
|
@ -18,6 +18,7 @@ import (
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/durationpb"
|
"google.golang.org/protobuf/types/known/durationpb"
|
||||||
|
"google.golang.org/protobuf/types/known/fieldmaskpb"
|
||||||
"google.golang.org/protobuf/types/known/structpb"
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
|
@ -84,6 +85,58 @@ func TestServer_Get(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServer_Patch(t *testing.T) {
|
||||||
|
cfg := newServerConfig()
|
||||||
|
srv := newServer(cfg)
|
||||||
|
|
||||||
|
s := &session.Session{
|
||||||
|
Id: "1",
|
||||||
|
OauthToken: &session.OAuthToken{AccessToken: "access-token"},
|
||||||
|
}
|
||||||
|
data := protoutil.NewAny(s)
|
||||||
|
_, err := srv.Put(context.Background(), &databroker.PutRequest{
|
||||||
|
Records: []*databroker.Record{{
|
||||||
|
Type: data.TypeUrl,
|
||||||
|
Id: s.Id,
|
||||||
|
Data: data,
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
fm, err := fieldmaskpb.New(s, "accessed_at")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
now := timestamppb.Now()
|
||||||
|
s.AccessedAt = now
|
||||||
|
s.OauthToken.AccessToken = "access-token-field-ignored"
|
||||||
|
data = protoutil.NewAny(s)
|
||||||
|
patchResponse, err := srv.Patch(context.Background(), &databroker.PatchRequest{
|
||||||
|
Records: []*databroker.Record{{
|
||||||
|
Type: data.TypeUrl,
|
||||||
|
Id: s.Id,
|
||||||
|
Data: data,
|
||||||
|
}},
|
||||||
|
FieldMask: fm,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
testutil.AssertProtoEqual(t, protoutil.NewAny(&session.Session{
|
||||||
|
Id: "1",
|
||||||
|
AccessedAt: now,
|
||||||
|
OauthToken: &session.OAuthToken{AccessToken: "access-token"},
|
||||||
|
}), patchResponse.GetRecord().GetData())
|
||||||
|
|
||||||
|
getResponse, err := srv.Get(context.Background(), &databroker.GetRequest{
|
||||||
|
Type: data.TypeUrl,
|
||||||
|
Id: s.Id,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
testutil.AssertProtoEqual(t, protoutil.NewAny(&session.Session{
|
||||||
|
Id: "1",
|
||||||
|
AccessedAt: now,
|
||||||
|
OauthToken: &session.OAuthToken{AccessToken: "access-token"},
|
||||||
|
}), getResponse.GetRecord().GetData())
|
||||||
|
}
|
||||||
|
|
||||||
func TestServer_Options(t *testing.T) {
|
func TestServer_Options(t *testing.T) {
|
||||||
cfg := newServerConfig()
|
cfg := newServerConfig()
|
||||||
srv := newServer(cfg)
|
srv := newServer(cfg)
|
||||||
|
|
|
@ -150,6 +150,15 @@ func (x *PutResponse) GetRecord() *Record {
|
||||||
return records[0]
|
return records[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRecord gets the first record, or nil if there are none.
|
||||||
|
func (x *PatchResponse) GetRecord() *Record {
|
||||||
|
records := x.GetRecords()
|
||||||
|
if len(records) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return records[0]
|
||||||
|
}
|
||||||
|
|
||||||
// SetFilterByID sets the filter to an id.
|
// SetFilterByID sets the filter to an id.
|
||||||
func (x *QueryRequest) SetFilterByID(id string) {
|
func (x *QueryRequest) SetFilterByID(id string) {
|
||||||
x.Filter = &structpb.Struct{Fields: map[string]*structpb.Value{
|
x.Filter = &structpb.Struct{Fields: map[string]*structpb.Value{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue