diff --git a/client/client_test.go b/client/client_test.go index 87987a83..0ff5d8a0 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -130,6 +130,23 @@ func TestDaemonUp(t *testing.T) { assert.Equal(t, actualCommand, session.Calls[0]) } +func TestDaemonDown(t *testing.T) { + session := &mockSSHRunner{} + client := newMockSSHClient(session) + client.version = "latest" + client.IP = "0.0.0.0" + client.Daemon.Port = "4303" + script, err := ioutil.ReadFile("scripts/daemon-down.sh") + assert.Nil(t, err) + actualCommand := fmt.Sprintf(string(script)) + + // Make sure the right command is run. + err = client.DaemonDown() + assert.Nil(t, err) + println(actualCommand) + assert.Equal(t, actualCommand, session.Calls[0]) +} + func TestKeyGen(t *testing.T) { session := &mockSSHRunner{} remote := newMockSSHClient(session) @@ -561,3 +578,68 @@ func TestLogIn(t *testing.T) { assert.Nil(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) } + +func TestEnableTotp(t *testing.T) { + testServer := httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + rw.WriteHeader(http.StatusOK) + + // Check request method + assert.Equal(t, "POST", req.Method) + + // Check correct endpoint called + endpoint := req.URL.Path + assert.Equal(t, "/user/totp/enable", endpoint) + + // Check auth + assert.Equal(t, "Bearer "+fakeAuth, req.Header.Get("Authorization")) + })) + defer testServer.Close() + + d := newMockClient(testServer) + resp, err := d.EnableTotp("", "") + assert.NoError(t, err) + assert.Equal(t, http.StatusOK, resp.StatusCode) +} + +func TestDisableTotp(t *testing.T) { + testServer := httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + rw.WriteHeader(http.StatusOK) + + // Check request method + assert.Equal(t, "POST", req.Method) + + // Check correct endpoint called + endpoint := req.URL.Path + assert.Equal(t, "/user/totp/disable", endpoint) + + // Check auth + assert.Equal(t, "Bearer "+fakeAuth, req.Header.Get("Authorization")) + })) + defer testServer.Close() + + d := newMockClient(testServer) + resp, err := d.DisableTotp() + assert.NoError(t, err) + assert.Equal(t, http.StatusOK, resp.StatusCode) +} + +func TestSetSSLVerification(t *testing.T) { + testServer := httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + rw.WriteHeader(http.StatusOK) + + // Check request method + assert.Equal(t, "POST", req.Method) + + // Check correct endpoint called + endpoint := req.URL.Path + assert.Equal(t, "/user/totp/disable", endpoint) + + // Check auth + assert.Equal(t, "Bearer "+fakeAuth, req.Header.Get("Authorization")) + })) + defer testServer.Close() + + d := newMockClient(testServer) + d.SetSSLVerification(true) + assert.Equal(t, d.verifySSL, true) +}