Skip to content

Commit

Permalink
fix search test with boundary token check (#3799)
Browse files Browse the repository at this point in the history
  • Loading branch information
talanknight authored Oct 5, 2023
1 parent 4c905ca commit aa43f9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
11 changes: 2 additions & 9 deletions internal/cmd/commands/daemon/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package daemon

import (
"context"
stdErrors "errors"
"io"
"sync"
"testing"
Expand Down Expand Up @@ -71,10 +70,10 @@ func (s *TestServer) Serve(t *testing.T, opt ...Option) error {

// AddResources adds targets to the cache for the provided address, token name,
// and keyring type. They token info must already be known to the server.
func (s *TestServer) AddResources(t *testing.T, p *authtokens.AuthToken, tars []*targets.Target, sess []*sessions.Session) {
func (s *TestServer) AddResources(t *testing.T, p *authtokens.AuthToken, tars []*targets.Target, sess []*sessions.Session, atReadFn cache.BoundaryTokenReaderFn) {
t.Helper()
ctx := context.Background()
r, err := cache.NewRepository(ctx, s.cacheServer.store, &sync.Map{}, s.cmd.ReadTokenFromKeyring, unimplementedAuthTokenReader)
r, err := cache.NewRepository(ctx, s.cacheServer.store, &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
require.NoError(t, err)

tarFn := func(ctx context.Context, _, tok string) ([]*targets.Target, error) {
Expand All @@ -91,9 +90,3 @@ func (s *TestServer) AddResources(t *testing.T, p *authtokens.AuthToken, tars []
}
require.NoError(t, r.Refresh(ctx, cache.WithTargetRetrievalFunc(tarFn), cache.WithSessionRetrievalFunc(sessFn)))
}

// unimplementedAuthTokenReader is an unimplemented function for reading auth
// tokens from a provided boundary address.
func unimplementedAuthTokenReader(ctx context.Context, addr string, authToken string) (*authtokens.AuthToken, error) {
return nil, stdErrors.New("unimplemented")
}
15 changes: 8 additions & 7 deletions internal/cmd/commands/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ func TestSearch(t *testing.T) {
ExpirationTime: time.Now().Add(time.Minute),
}
cmd := &testCommander{t: t, at: at}
boundaryTokenReaderFn := func(ctx context.Context, addr, authToken string) (*authtokens.AuthToken, error) {
if authToken == at.Token {
return at, nil
}
return nil, errors.New("test not found error")
}

srv := daemon.NewTestServer(t, cmd)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
srv.Serve(t, daemon.WithBoundaryTokenReaderFunc(ctx, func(ctx context.Context, addr, authToken string) (*authtokens.AuthToken, error) {
if authToken == at.Token {
return at, nil
}
return nil, errors.New("test not found error")
}))
srv.Serve(t, daemon.WithBoundaryTokenReaderFunc(ctx, boundaryTokenReaderFn))
}()
// Give the store some time to get initialized
time.Sleep(100 * time.Millisecond)
Expand Down Expand Up @@ -161,7 +162,7 @@ func TestSearch(t *testing.T) {
}, []*sessions.Session{
{Id: "sess_1234567890", TargetId: "ttcp_1234567890", Status: "pending"},
{Id: "sess_0987654321", TargetId: "ttcp_0987654321", Status: "pending"},
})
}, boundaryTokenReaderFn)

t.Run("target response from list", func(t *testing.T) {
resp, err := search(ctx, srv.BaseSocketDir(), filterBy{
Expand Down

0 comments on commit aa43f9a

Please sign in to comment.