mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-31 01:47:33 +02:00
fix redirect loop, remove user/session services, remove duplicate deleted_at fields (#1162)
* fix redirect loop, remove user/session services, remove duplicate deleted_at fields * change loop * reuse err variable * wrap errors, use cookie timeout * wrap error, duplicate if
This commit is contained in:
parent
714363fb07
commit
97f85481f8
16 changed files with 288 additions and 918 deletions
|
@ -140,6 +140,9 @@ func (srv *Server) Get(ctx context.Context, req *databroker.GetRequest) (*databr
|
|||
if err != nil {
|
||||
return nil, status.Error(codes.NotFound, "record not found")
|
||||
}
|
||||
if record.DeletedAt != nil {
|
||||
return nil, status.Error(codes.NotFound, "record not found")
|
||||
}
|
||||
return &databroker.GetResponse{Record: record}, nil
|
||||
}
|
||||
|
||||
|
@ -155,16 +158,27 @@ func (srv *Server) GetAll(ctx context.Context, req *databroker.GetAllRequest) (*
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
records, err := db.GetAll(ctx)
|
||||
|
||||
all, err := db.GetAll(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(all) == 0 {
|
||||
return &databroker.GetAllResponse{ServerVersion: srv.version}, nil
|
||||
}
|
||||
|
||||
var recordVersion string
|
||||
for _, record := range records {
|
||||
records := make([]*databroker.Record, 0, len(all))
|
||||
for _, record := range all {
|
||||
if record.GetVersion() > recordVersion {
|
||||
recordVersion = record.GetVersion()
|
||||
}
|
||||
if record.DeletedAt == nil {
|
||||
records = append(records, record)
|
||||
}
|
||||
}
|
||||
|
||||
return &databroker.GetAllResponse{
|
||||
ServerVersion: srv.version,
|
||||
RecordVersion: recordVersion,
|
||||
|
|
|
@ -8,10 +8,14 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
"github.com/pomerium/pomerium/internal/signal"
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
"github.com/pomerium/pomerium/pkg/grpc/session"
|
||||
"github.com/pomerium/pomerium/pkg/storage"
|
||||
)
|
||||
|
||||
|
@ -80,3 +84,58 @@ func TestServer_initVersion(t *testing.T) {
|
|||
assert.Equal(t, srvVersion, srv.version)
|
||||
})
|
||||
}
|
||||
|
||||
func TestServer_Get(t *testing.T) {
|
||||
cfg := newServerConfig()
|
||||
t.Run("ignore deleted", func(t *testing.T) {
|
||||
srv := newServer(cfg)
|
||||
|
||||
s := new(session.Session)
|
||||
s.Id = "1"
|
||||
any, err := anypb.New(s)
|
||||
assert.NoError(t, err)
|
||||
|
||||
srv.Set(context.Background(), &databroker.SetRequest{
|
||||
Type: any.TypeUrl,
|
||||
Id: s.Id,
|
||||
Data: any,
|
||||
})
|
||||
srv.Delete(context.Background(), &databroker.DeleteRequest{
|
||||
Type: any.TypeUrl,
|
||||
Id: s.Id,
|
||||
})
|
||||
_, err = srv.Get(context.Background(), &databroker.GetRequest{
|
||||
Type: any.TypeUrl,
|
||||
Id: s.Id,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, codes.NotFound, status.Code(err))
|
||||
})
|
||||
}
|
||||
|
||||
func TestServer_GetAll(t *testing.T) {
|
||||
cfg := newServerConfig()
|
||||
t.Run("ignore deleted", func(t *testing.T) {
|
||||
srv := newServer(cfg)
|
||||
|
||||
s := new(session.Session)
|
||||
s.Id = "1"
|
||||
any, err := anypb.New(s)
|
||||
assert.NoError(t, err)
|
||||
|
||||
srv.Set(context.Background(), &databroker.SetRequest{
|
||||
Type: any.TypeUrl,
|
||||
Id: s.Id,
|
||||
Data: any,
|
||||
})
|
||||
srv.Delete(context.Background(), &databroker.DeleteRequest{
|
||||
Type: any.TypeUrl,
|
||||
Id: s.Id,
|
||||
})
|
||||
res, err := srv.GetAll(context.Background(), &databroker.GetAllRequest{
|
||||
Type: any.TypeUrl,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, res.GetRecords(), 0)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue