Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search test with boundary token check #3799

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading