MCPcopy
hub / github.com/kopia/kopia / TestServerUserHashPassword

Function TestServerUserHashPassword

cli/command_user_hash_password_test.go:14–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestServerUserHashPassword(t *testing.T) {
15 const (
16 userName = "user78"
17 userHost = "client-host"
18 userFull = userName + "@" + userHost
19 )
20
21 runner := testenv.NewInProcRunner(t)
22 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
23
24 e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir, "--override-username", "server", "--override-hostname", "host")
25
26 t.Cleanup(func() {
27 e.RunAndExpectSuccess(t, "repo", "disconnect")
28 })
29
30 userPassword := "bad-password-" + strconv.Itoa(int(rand.Int31()))
31
32 out := e.RunAndExpectSuccess(t, "server", "users", "hash-password", "--user-password", userPassword)
33
34 require.Len(t, out, 1)
35
36 passwordHash := out[0]
37 require.NotEmpty(t, passwordHash)
38
39 // attempt to create a user with a bad password hash
40 e.RunAndExpectFailure(t, "server", "users", "add", userFull, "--user-password-hash", "bad-base64")
41
42 // create a new user with and set the password using the password hash
43 e.RunAndExpectSuccess(t, "server", "users", "add", userFull, "--user-password-hash", passwordHash)
44
45 // start server to test accessing the server with user created above
46 var sp testutil.ServerParameters
47
48 wait, kill := e.RunAndProcessStderr(t, sp.ProcessOutput,
49 "server", "start",
50 "--address=localhost:0",
51 "--tls-generate-cert",
52 "--random-server-control-password",
53 "--shutdown-grace-period", "100ms",
54 )
55
56 t.Cleanup(func() {
57 kill()
58 wait()
59 t.Log("server stopped")
60 })
61
62 t.Logf("detected server parameters %#v", sp)
63
64 // connect to the server repo using a client with the user created above
65 cr := testenv.NewInProcRunner(t)
66 clientEnv := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, cr)
67
68 delete(clientEnv.Environment, "KOPIA_PASSWORD")
69
70 clientEnv.RunAndExpectSuccess(t, "repo", "connect", "server",
71 "--url", sp.BaseURL,

Callers

nothing calls this directly

Calls 9

RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95
RunAndProcessStderrMethod · 0.95
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
LogMethod · 0.80
LogfMethod · 0.80
CleanupMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected