As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit eede646c authored by Ash McKenzie's avatar Ash McKenzie
Browse files

Pass testRoot in where needed

parent fa2e1e5c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -56,7 +56,8 @@ func buildExpectedResponse(who string) *Response {
}
func TestSuccessfulResponses(t *testing.T) {
okResponse := testResponse{body: responseBody(t, "allowed.json"), status: http.StatusOK}
testRoot := testhelper.PrepareTestRootDir(t)
okResponse := testResponse{body: responseBody(t, testRoot, "allowed.json"), status: http.StatusOK}
client := setup(t,
map[string]testResponse{"first": okResponse, "test@TEST.TEST": okResponse},
map[string]testResponse{"1": okResponse},
Loading
Loading
@@ -94,9 +95,10 @@ func TestSuccessfulResponses(t *testing.T) {
}
func TestGeoPushGetCustomAction(t *testing.T) {
testRoot := testhelper.PrepareTestRootDir(t)
client := setup(t, map[string]testResponse{
"custom": {
body: responseBody(t, "allowed_with_push_payload.json"),
body: responseBody(t, testRoot, "allowed_with_push_payload.json"),
status: 300,
},
}, nil)
Loading
Loading
@@ -123,9 +125,10 @@ func TestGeoPushGetCustomAction(t *testing.T) {
}
func TestGeoPullGetCustomAction(t *testing.T) {
testRoot := testhelper.PrepareTestRootDir(t)
client := setup(t, map[string]testResponse{
"custom": {
body: responseBody(t, "allowed_with_pull_payload.json"),
body: responseBody(t, testRoot, "allowed_with_pull_payload.json"),
status: 300,
},
}, nil)
Loading
Loading
@@ -241,9 +244,8 @@ type testResponse struct {
status int
}
func responseBody(t *testing.T, name string) []byte {
func responseBody(t *testing.T, testRoot, name string) []byte {
t.Helper()
testRoot := testhelper.PrepareTestRootDir(t)
body, err := os.ReadFile(path.Join(testRoot, "responses", name))
require.NoError(t, err)
return body
Loading
Loading
Loading
Loading
@@ -32,9 +32,9 @@ var (
)
func TestListenAndServe(t *testing.T) {
s := setupServer(t)
s, testRoot := setupServer(t)
client, err := ssh.Dial("tcp", serverUrl, clientConfig(t))
client, err := ssh.Dial("tcp", serverUrl, clientConfig(t, testRoot))
require.NoError(t, err)
defer client.Close()
Loading
Loading
@@ -43,7 +43,7 @@ func TestListenAndServe(t *testing.T) {
holdSession(t, client)
_, err = ssh.Dial("tcp", serverUrl, clientConfig(t))
_, err = ssh.Dial("tcp", serverUrl, clientConfig(t, testRoot))
require.Equal(t, err.Error(), "dial tcp 127.0.0.1:50000: connect: connection refused")
client.Close()
Loading
Loading
@@ -52,6 +52,8 @@ func TestListenAndServe(t *testing.T) {
}
func TestListenAndServe_proxyProtocolEnabled(t *testing.T) {
testRoot := testhelper.PrepareTestRootDir(t)
target, err := net.ResolveTCPAddr("tcp", serverUrl)
require.NoError(t, err)
Loading
Loading
@@ -193,7 +195,7 @@ func TestListenAndServe_proxyProtocolEnabled(t *testing.T) {
require.NoError(t, err)
}
sshConn, sshChans, sshRequs, err := ssh.NewClientConn(conn, serverUrl, clientConfig(t))
sshConn, sshChans, sshRequs, err := ssh.NewClientConn(conn, serverUrl, clientConfig(t, testRoot))
if sshConn != nil {
defer sshConn.Close()
}
Loading
Loading
@@ -213,9 +215,9 @@ func TestListenAndServe_proxyProtocolEnabled(t *testing.T) {
}
func TestCorrelationId(t *testing.T) {
setupServer(t)
_, testRoot := setupServer(t)
client, err := ssh.Dial("tcp", serverUrl, clientConfig(t))
client, err := ssh.Dial("tcp", serverUrl, clientConfig(t, testRoot))
require.NoError(t, err)
defer client.Close()
Loading
Loading
@@ -223,7 +225,7 @@ func TestCorrelationId(t *testing.T) {
previousCorrelationId := correlationId
client, err = ssh.Dial("tcp", serverUrl, clientConfig(t))
client, err = ssh.Dial("tcp", serverUrl, clientConfig(t, testRoot))
require.NoError(t, err)
defer client.Close()
Loading
Loading
@@ -270,9 +272,9 @@ func TestLivenessProbe(t *testing.T) {
}
func TestInvalidClientConfig(t *testing.T) {
setupServer(t)
_, testRoot := setupServer(t)
cfg := clientConfig(t)
cfg := clientConfig(t, testRoot)
cfg.User = "unknown"
_, err := ssh.Dial("tcp", serverUrl, cfg)
require.Error(t, err)
Loading
Loading
@@ -291,12 +293,12 @@ func TestClosingHangedConnections(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := setupServerWithContext(t, nil, ctx)
s, testRoot := setupServerWithContext(t, nil, ctx)
unauthenticatedRequestStatus := make(chan string)
completed := make(chan bool)
clientCfg := clientConfig(t)
clientCfg := clientConfig(t, testRoot)
clientCfg.HostKeyCallback = func(_ string, _ net.Addr, _ ssh.PublicKey) error {
unauthenticatedRequestStatus <- "authentication-started"
<-completed // Wait infinitely
Loading
Loading
@@ -322,12 +324,12 @@ func TestLoginGraceTime(t *testing.T) {
LoginGraceTime: config.YamlDuration(50 * time.Millisecond),
},
}
s := setupServerWithConfig(t, cfg)
s, testRoot := setupServerWithConfig(t, cfg)
unauthenticatedRequestStatus := make(chan string)
completed := make(chan bool)
clientCfg := clientConfig(t)
clientCfg := clientConfig(t, testRoot)
clientCfg.HostKeyCallback = func(_ string, _ net.Addr, _ ssh.PublicKey) error {
unauthenticatedRequestStatus <- "authentication-started"
<-completed // Wait infinitely
Loading
Loading
@@ -374,21 +376,23 @@ func TestExtractMetaDataFromNilContext(t *testing.T) {
require.Equal(t, command.LogData{}, data)
}
func setupServer(t *testing.T) *Server {
func setupServer(t *testing.T) (*Server, string) {
t.Helper()
return setupServerWithConfig(t, nil)
}
func setupServerWithConfig(t *testing.T, cfg *config.Config) *Server {
func setupServerWithConfig(t *testing.T, cfg *config.Config) (*Server, string) {
t.Helper()
return setupServerWithContext(t, cfg, context.Background())
}
func setupServerWithContext(t *testing.T, cfg *config.Config, ctx context.Context) *Server {
func setupServerWithContext(t *testing.T, cfg *config.Config, ctx context.Context) (*Server, string) {
t.Helper()
testRoot := testhelper.PrepareTestRootDir(t)
requests := []testserver.TestRequestHandler{
{
Path: "/api/v4/internal/authorized_keys",
Loading
Loading
@@ -411,8 +415,6 @@ func setupServerWithContext(t *testing.T, cfg *config.Config, ctx context.Contex
},
}
testRoot := testhelper.PrepareTestRootDir(t)
url := testserver.StartSocketHttpServer(t, requests)
if cfg == nil {
Loading
Loading
@@ -435,12 +437,10 @@ func setupServerWithContext(t *testing.T, cfg *config.Config, ctx context.Contex
verifyStatus(t, s, StatusReady)
return s
return s, testRoot
}
func clientConfig(t *testing.T) *ssh.ClientConfig {
testRoot := testhelper.PrepareTestRootDir(t)
func clientConfig(t *testing.T, testRoot string) *ssh.ClientConfig {
keyRaw, err := os.ReadFile(path.Join(testRoot, "certs/valid/server_authorized_key"))
pKey, _, _, _, err := ssh.ParseAuthorizedKey(keyRaw)
require.NoError(t, err)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment