From 702d734df9caff02bdf207a61d7816b7fddd57b8 Mon Sep 17 00:00:00 2001 From: Leoswaldo Macias Date: Fri, 29 Jul 2016 16:33:24 -0500 Subject: [PATCH 1/5] ciao-controller: add test of listFlavorsDetails The function listFlavorsDetails didn't unit testing for code coverage, this commit includes only the code coverage for the happy path. The listFlavorsDetails method servers the api method call to describe the details for all flavors existent of a given tenant Fixes #349 Signed-off-by: Leoswaldo Macias --- ciao-controller/compute_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ciao-controller/compute_test.go b/ciao-controller/compute_test.go index b7e873859..d9ad0ec3e 100644 --- a/ciao-controller/compute_test.go +++ b/ciao-controller/compute_test.go @@ -510,6 +510,17 @@ func TestShowFlavorDetails(t *testing.T) { } } +func TestListFlavorsDetails(t *testing.T) { + tenant, err := context.ds.GetTenant(testutil.ComputeUser) + if err != nil { + t.Fatal(err) + } + + url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/flavors/detail" + + _ = testHTTPRequest(t, "GET", url, http.StatusOK, nil) +} + func TestListTenantResources(t *testing.T) { var usage payloads.CiaoUsageHistory From a9f3c9554c2a727770bb9749158993789d0a28bb Mon Sep 17 00:00:00 2001 From: Leoswaldo Macias Date: Mon, 1 Aug 2016 11:53:19 -0500 Subject: [PATCH 2/5] ciao-controller: enable testHTTPRequest to send invalid token The function testHTTPRequest is used to send the http requests, and it always sends requests with valid tokens, we are enabling it to send invalid tokens for negative test cases to fail in authentication by not sending the token in the request if the validToken variable is false. Now all calls to testHTTPRequest need to specify if the should have a valid token or not. Fixes #349 Signed-off-by: Leoswaldo Macias --- ciao-controller/compute_test.go | 59 +++++++++++++++++---------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/ciao-controller/compute_test.go b/ciao-controller/compute_test.go index d9ad0ec3e..98d77663d 100644 --- a/ciao-controller/compute_test.go +++ b/ciao-controller/compute_test.go @@ -31,9 +31,12 @@ import ( "github.com/01org/ciao/testutil" ) -func testHTTPRequest(t *testing.T, method string, URL string, expectedResponse int, data []byte) []byte { +func testHTTPRequest(t *testing.T, method string, URL string, expectedResponse int, data []byte, validToken bool) []byte { req, err := http.NewRequest(method, URL, bytes.NewBuffer(data)) - req.Header.Set("X-Auth-Token", "imavalidtoken") + + if validToken { + req.Header.Set("X-Auth-Token", "imavalidtoken") + } if data != nil { req.Header.Set("Content-Type", "application/json") } @@ -91,7 +94,7 @@ func testCreateServer(t *testing.T, n int) payloads.ComputeServers { t.Fatal(err) } - body := testHTTPRequest(t, "POST", url, http.StatusAccepted, b) + body := testHTTPRequest(t, "POST", url, http.StatusAccepted, b, true) servers := payloads.NewComputeServers() @@ -110,7 +113,7 @@ func testCreateServer(t *testing.T, n int) payloads.ComputeServers { func testListServerDetailsTenant(t *testing.T, tenantID string) payloads.ComputeServers { url := testutil.ComputeURL + "/v2.1/" + tenantID + "/servers/detail" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) s := payloads.NewComputeServers() err := json.Unmarshal(body, &s) @@ -161,7 +164,7 @@ func TestListServerDetailsWorkload(t *testing.T) { url := testutil.ComputeURL + "/v2.1/flavors/" + wls[0].ID + "/servers/detail" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var s payloads.ComputeServers err = json.Unmarshal(body, &s) @@ -196,7 +199,7 @@ func TestShowServerDetails(t *testing.T) { for _, s1 := range s.Servers { url := tURL + s1.ID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var s2 payloads.ComputeServer err = json.Unmarshal(body, &s2) @@ -246,9 +249,9 @@ func TestDeleteServer(t *testing.T) { for _, s1 := range s.Servers { url := tURL + s1.ID if s1.HostID != "" { - _ = testHTTPRequest(t, "DELETE", url, http.StatusAccepted, nil) + _ = testHTTPRequest(t, "DELETE", url, http.StatusAccepted, nil, true) } else { - _ = testHTTPRequest(t, "DELETE", url, http.StatusInternalServerError, nil) + _ = testHTTPRequest(t, "DELETE", url, http.StatusInternalServerError, nil, true) } } @@ -303,7 +306,7 @@ func TestServersActionStart(t *testing.T) { t.Fatal(err) } - _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b) + _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b, true) } func TestServersActionStop(t *testing.T) { @@ -344,7 +347,7 @@ func TestServersActionStop(t *testing.T) { t.Fatal(err) } - _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b) + _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b, true) } func TestServerActionStop(t *testing.T) { @@ -373,7 +376,7 @@ func TestServerActionStop(t *testing.T) { time.Sleep(1 * time.Second) url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/servers/" + servers.Servers[0].ID + "/action" - _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, []byte(action)) + _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, []byte(action), true) } func TestServerActionStart(t *testing.T) { @@ -420,7 +423,7 @@ func TestServerActionStart(t *testing.T) { time.Sleep(1 * time.Second) url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/servers/" + servers.Servers[0].ID + "/action" - _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, []byte(action)) + _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, []byte(action), true) } func TestListFlavors(t *testing.T) { @@ -436,7 +439,7 @@ func TestListFlavors(t *testing.T) { t.Fatal(err) } - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var flavors payloads.ComputeFlavors err = json.Unmarshal(body, &flavors) @@ -495,7 +498,7 @@ func TestShowFlavorDetails(t *testing.T) { } url := tURL + w.ID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var f payloads.ComputeFlavorDetails @@ -518,7 +521,7 @@ func TestListFlavorsDetails(t *testing.T) { url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/flavors/detail" - _ = testHTTPRequest(t, "GET", url, http.StatusOK, nil) + _ = testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) } func TestListTenantResources(t *testing.T) { @@ -545,7 +548,7 @@ func TestListTenantResources(t *testing.T) { tURL += v.Encode() - body := testHTTPRequest(t, "GET", tURL, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", tURL, http.StatusOK, nil, true) var result payloads.CiaoUsageHistory @@ -591,7 +594,7 @@ func TestListTenantQuotas(t *testing.T) { expected.ID = tenant.ID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoTenantResources @@ -636,7 +639,7 @@ func TestListEventsTenant(t *testing.T) { expected.Events = append(expected.Events, event) } - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoEvents @@ -661,7 +664,7 @@ func TestListNodeServers(t *testing.T) { url := testutil.ComputeURL + "/v2.1/nodes/" + n.ID + "/servers/detail" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoServersStats @@ -702,7 +705,7 @@ func TestListTenants(t *testing.T) { url := testutil.ComputeURL + "/v2.1/tenants" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoComputeTenants @@ -742,7 +745,7 @@ func TestListNodes(t *testing.T) { url := testutil.ComputeURL + "/v2.1/nodes" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoComputeNodes @@ -780,7 +783,7 @@ func TestNodeSummary(t *testing.T) { url := testutil.ComputeURL + "/v2.1/nodes/summary" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoClusterStatus @@ -829,7 +832,7 @@ func TestListCNCIs(t *testing.T) { url := testutil.ComputeURL + "/v2.1/cncis" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoCNCIs @@ -879,7 +882,7 @@ func TestListCNCIDetails(t *testing.T) { url := testutil.ComputeURL + "/v2.1/cncis/" + cnci.InstanceID + "/detail" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoCNCI @@ -919,7 +922,7 @@ func TestListTraces(t *testing.T) { url := testutil.ComputeURL + "/v2.1/traces" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoTracesSummary @@ -953,7 +956,7 @@ func TestListEvents(t *testing.T) { expected.Events = append(expected.Events, event) } - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoEvents @@ -970,7 +973,7 @@ func TestListEvents(t *testing.T) { func TestClearEvents(t *testing.T) { url := testutil.ComputeURL + "/v2.1/events" - _ = testHTTPRequest(t, "DELETE", url, http.StatusAccepted, nil) + _ = testHTTPRequest(t, "DELETE", url, http.StatusAccepted, nil, true) logs, err := context.ds.GetEventLog() if err != nil { @@ -1017,7 +1020,7 @@ func TestTraceData(t *testing.T) { url := testutil.ComputeURL + "/v2.1/traces/" + s.BatchID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil) + body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) var result payloads.CiaoTraceData From 24b7c2da710db69b1b65c45eda424ec863e113de Mon Sep 17 00:00:00 2001 From: Leoswaldo Macias Date: Tue, 2 Aug 2016 09:52:43 -0500 Subject: [PATCH 3/5] ciao-controller: convert compute test cases into templates Compute tests is only covering happy paths, we are converting all testcases into templates, this way we can re-use their code to cover also negative cases, such as invalid authentication and other scenarios. With this change we use the template to avoid duplicating code when covering same functionality. Also this commit contains the required changes for the testcases that cover the happy path to use its corresponding template. The idea of the template is that we can reuse it and only call with different parameters, we might need to change the templates for coming test integrations but would be minimal changes and would keep the code cleaner that if we start duplicating code. Templates created: - testCreateServer - testListServerDetailsTenant - testListServerDetailsWorkload - testShowServerDetails - testDeleteServer - testServersActionStart - testServerActionStop - testListFlavors - testShowFlavorDetails - testListFlavorsDetails - testListTenantResources - testListTenantQuotas - testListEventsTenant - testListNodeServers - testListTenants - testListNodes - testNodeSummary - testListCNCIs - testListCNCIDetails - testListTraces - testListEvents - testClearEvents - testTraceData Fixes #349 Signed-off-by: Leoswaldo Macias --- ciao-controller/compute_test.go | 170 +++++++++++++++++++++++--------- 1 file changed, 126 insertions(+), 44 deletions(-) diff --git a/ciao-controller/compute_test.go b/ciao-controller/compute_test.go index 98d77663d..94af72320 100644 --- a/ciao-controller/compute_test.go +++ b/ciao-controller/compute_test.go @@ -146,7 +146,7 @@ func TestListServerDetailsTenant(t *testing.T) { } } -func TestListServerDetailsWorkload(t *testing.T) { +func testListServerDetailsWorkload(t *testing.T, httpExpectedStatus int, validToken bool) { // get a valid workload ID wls, err := context.ds.GetWorkloads() if err != nil { @@ -164,7 +164,7 @@ func TestListServerDetailsWorkload(t *testing.T) { url := testutil.ComputeURL + "/v2.1/flavors/" + wls[0].ID + "/servers/detail" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var s payloads.ComputeServers err = json.Unmarshal(body, &s) @@ -177,7 +177,11 @@ func TestListServerDetailsWorkload(t *testing.T) { } } -func TestShowServerDetails(t *testing.T) { +func TestListServerDetailsWorkload(t *testing.T) { + testListServerDetailsWorkload(t, http.StatusOK, true) +} + +func testShowServerDetails(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -199,7 +203,7 @@ func TestShowServerDetails(t *testing.T) { for _, s1 := range s.Servers { url := tURL + s1.ID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var s2 payloads.ComputeServer err = json.Unmarshal(body, &s2) @@ -214,7 +218,11 @@ func TestShowServerDetails(t *testing.T) { } } -func TestDeleteServer(t *testing.T) { +func TestShowServerDetails(t *testing.T) { + testShowServerDetails(t, http.StatusOK, true) +} + +func testDeleteServer(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -249,15 +257,18 @@ func TestDeleteServer(t *testing.T) { for _, s1 := range s.Servers { url := tURL + s1.ID if s1.HostID != "" { - _ = testHTTPRequest(t, "DELETE", url, http.StatusAccepted, nil, true) + _ = testHTTPRequest(t, "DELETE", url, httpExpectedStatus, nil, validToken) } else { - _ = testHTTPRequest(t, "DELETE", url, http.StatusInternalServerError, nil, true) + _ = testHTTPRequest(t, "DELETE", url, http.StatusInternalServerError, nil, validToken) } - } } -func TestServersActionStart(t *testing.T) { +func TestDeleteServer(t *testing.T) { + testDeleteServer(t, http.StatusAccepted, true) +} + +func testServersActionStart(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -306,7 +317,11 @@ func TestServersActionStart(t *testing.T) { t.Fatal(err) } - _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b, true) + _ = testHTTPRequest(t, "POST", url, httpExpectedStatus, b, validToken) +} + +func TestServersActionStart(t *testing.T) { + testServersActionStart(t, http.StatusAccepted, true) } func TestServersActionStop(t *testing.T) { @@ -350,7 +365,7 @@ func TestServersActionStop(t *testing.T) { _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b, true) } -func TestServerActionStop(t *testing.T) { +func testServerActionStop(t *testing.T, httpExpectedStatus int, validToken bool) { action := "os-stop" tenant, err := context.ds.GetTenant(testutil.ComputeUser) @@ -376,7 +391,11 @@ func TestServerActionStop(t *testing.T) { time.Sleep(1 * time.Second) url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/servers/" + servers.Servers[0].ID + "/action" - _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, []byte(action), true) + _ = testHTTPRequest(t, "POST", url, httpExpectedStatus, []byte(action), validToken) +} + +func TestServerActionStop(t *testing.T) { + testServerActionStop(t, http.StatusAccepted, true) } func TestServerActionStart(t *testing.T) { @@ -426,7 +445,7 @@ func TestServerActionStart(t *testing.T) { _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, []byte(action), true) } -func TestListFlavors(t *testing.T) { +func testListFlavors(t *testing.T, httpExpectedStatus int, data []byte, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -439,7 +458,7 @@ func TestListFlavors(t *testing.T) { t.Fatal(err) } - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, data, validToken) var flavors payloads.ComputeFlavors err = json.Unmarshal(body, &flavors) @@ -466,7 +485,11 @@ func TestListFlavors(t *testing.T) { } } -func TestShowFlavorDetails(t *testing.T) { +func TestListFlavors(t *testing.T) { + testListFlavors(t, http.StatusOK, nil, true) +} + +func testShowFlavorDetails(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -498,7 +521,7 @@ func TestShowFlavorDetails(t *testing.T) { } url := tURL + w.ID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var f payloads.ComputeFlavorDetails @@ -513,18 +536,25 @@ func TestShowFlavorDetails(t *testing.T) { } } -func TestListFlavorsDetails(t *testing.T) { +func TestShowFlavorDetails(t *testing.T) { + testShowFlavorDetails(t, http.StatusOK, true) +} + +func testListFlavorsDetails(t *testing.T, httpExpectedStatus int, data []byte, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) } url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/flavors/detail" + _ = testHTTPRequest(t, "GET", url, httpExpectedStatus, data, validToken) +} - _ = testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) +func TestListFlavorsDetails(t *testing.T) { + testListFlavorsDetails(t, http.StatusOK, nil, true) } -func TestListTenantResources(t *testing.T) { +func testListTenantResources(t *testing.T, httpExpectedStatus int, validToken bool) { var usage payloads.CiaoUsageHistory endTime := time.Now() @@ -548,7 +578,7 @@ func TestListTenantResources(t *testing.T) { tURL += v.Encode() - body := testHTTPRequest(t, "GET", tURL, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", tURL, httpExpectedStatus, nil, validToken) var result payloads.CiaoUsageHistory @@ -562,7 +592,11 @@ func TestListTenantResources(t *testing.T) { } } -func TestListTenantQuotas(t *testing.T) { +func TestListTenantResources(t *testing.T) { + testListTenantResources(t, http.StatusOK, true) +} + +func testListTenantQuotas(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -594,7 +628,7 @@ func TestListTenantQuotas(t *testing.T) { expected.ID = tenant.ID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoTenantResources @@ -610,7 +644,11 @@ func TestListTenantQuotas(t *testing.T) { } } -func TestListEventsTenant(t *testing.T) { +func TestListTenantQuotas(t *testing.T) { + testListTenantQuotas(t, http.StatusOK, true) +} + +func testListEventsTenant(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -639,7 +677,7 @@ func TestListEventsTenant(t *testing.T) { expected.Events = append(expected.Events, event) } - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoEvents @@ -653,7 +691,11 @@ func TestListEventsTenant(t *testing.T) { } } -func TestListNodeServers(t *testing.T) { +func TestListEventsTenant(t *testing.T) { + testListEventsTenant(t, http.StatusOK, true) +} + +func testListNodeServers(t *testing.T, httpExpectedStatus int, validToken bool) { computeNodes := context.ds.GetNodeLastStats() for _, n := range computeNodes.Nodes { @@ -664,7 +706,7 @@ func TestListNodeServers(t *testing.T) { url := testutil.ComputeURL + "/v2.1/nodes/" + n.ID + "/servers/detail" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoServersStats @@ -683,7 +725,11 @@ func TestListNodeServers(t *testing.T) { } } -func TestListTenants(t *testing.T) { +func TestListNodeServers(t *testing.T) { + testListNodeServers(t, http.StatusOK, true) +} + +func testListTenants(t *testing.T, httpExpectedStatus int, validToken bool) { tenants, err := context.ds.GetAllTenants() if err != nil { t.Fatal(err) @@ -705,7 +751,7 @@ func TestListTenants(t *testing.T) { url := testutil.ComputeURL + "/v2.1/tenants" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoComputeTenants @@ -719,7 +765,11 @@ func TestListTenants(t *testing.T) { } } -func TestListNodes(t *testing.T) { +func TestListTenants(t *testing.T) { + testListTenants(t, http.StatusOK, true) +} + +func testListNodes(t *testing.T, httpExpectedStatus int, validToken bool) { expected := context.ds.GetNodeLastStats() summary, err := context.ds.GetNodeSummary() @@ -745,7 +795,7 @@ func TestListNodes(t *testing.T) { url := testutil.ComputeURL + "/v2.1/nodes" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoComputeNodes @@ -763,7 +813,11 @@ func TestListNodes(t *testing.T) { } } -func TestNodeSummary(t *testing.T) { +func TestListNodes(t *testing.T) { + testListNodes(t, http.StatusOK, true) +} + +func testNodeSummary(t *testing.T, httpExpectedStatus int, validToken bool) { var expected payloads.CiaoClusterStatus computeNodes := context.ds.GetNodeLastStats() @@ -783,7 +837,7 @@ func TestNodeSummary(t *testing.T) { url := testutil.ComputeURL + "/v2.1/nodes/summary" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoClusterStatus @@ -797,7 +851,11 @@ func TestNodeSummary(t *testing.T) { } } -func TestListCNCIs(t *testing.T) { +func TestNodeSummary(t *testing.T) { + testNodeSummary(t, http.StatusOK, true) +} + +func testListCNCIs(t *testing.T, httpExpectedStatus int, validToken bool) { var expected payloads.CiaoCNCIs cncis, err := context.ds.GetTenantCNCISummary("") @@ -832,7 +890,7 @@ func TestListCNCIs(t *testing.T) { url := testutil.ComputeURL + "/v2.1/cncis" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoCNCIs @@ -846,7 +904,11 @@ func TestListCNCIs(t *testing.T) { } } -func TestListCNCIDetails(t *testing.T) { +func TestListCNCIs(t *testing.T) { + testListCNCIs(t, http.StatusOK, true) +} + +func testListCNCIDetails(t *testing.T, httpExpectedStatus int, validToken bool) { cncis, err := context.ds.GetTenantCNCISummary("") if err != nil { t.Fatal(err) @@ -882,7 +944,7 @@ func TestListCNCIDetails(t *testing.T) { url := testutil.ComputeURL + "/v2.1/cncis/" + cnci.InstanceID + "/detail" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoCNCI @@ -897,7 +959,11 @@ func TestListCNCIDetails(t *testing.T) { } } -func TestListTraces(t *testing.T) { +func TestListCNCIDetails(t *testing.T) { + testListCNCIDetails(t, http.StatusOK, true) +} + +func testListTraces(t *testing.T, httpExpectedStatus int, validToken bool) { var expected payloads.CiaoTracesSummary client := testStartTracedWorkload(t) @@ -922,7 +988,7 @@ func TestListTraces(t *testing.T) { url := testutil.ComputeURL + "/v2.1/traces" - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoTracesSummary @@ -936,7 +1002,11 @@ func TestListTraces(t *testing.T) { } } -func TestListEvents(t *testing.T) { +func TestListTraces(t *testing.T) { + testListTraces(t, http.StatusOK, true) +} + +func testListEvents(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/events" expected := payloads.NewCiaoEvents() @@ -956,7 +1026,7 @@ func TestListEvents(t *testing.T) { expected.Events = append(expected.Events, event) } - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoEvents @@ -970,10 +1040,14 @@ func TestListEvents(t *testing.T) { } } -func TestClearEvents(t *testing.T) { +func TestListEvents(t *testing.T) { + testListEvents(t, http.StatusOK, true) +} + +func testClearEvents(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/events" - _ = testHTTPRequest(t, "DELETE", url, http.StatusAccepted, nil, true) + _ = testHTTPRequest(t, "DELETE", url, httpExpectedStatus, nil, validToken) logs, err := context.ds.GetEventLog() if err != nil { @@ -985,7 +1059,11 @@ func TestClearEvents(t *testing.T) { } } -func TestTraceData(t *testing.T) { +func TestClearEvents(t *testing.T) { + testClearEvents(t, http.StatusAccepted, true) +} + +func testTraceData(t *testing.T, httpExpectedStatus int, validToken bool) { client := testStartTracedWorkload(t) defer client.Ssntp.Close() @@ -1020,7 +1098,7 @@ func TestTraceData(t *testing.T) { url := testutil.ComputeURL + "/v2.1/traces/" + s.BatchID - body := testHTTPRequest(t, "GET", url, http.StatusOK, nil, true) + body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) var result payloads.CiaoTraceData @@ -1034,3 +1112,7 @@ func TestTraceData(t *testing.T) { } } } + +func TestTraceData(t *testing.T) { + testTraceData(t, http.StatusOK, true) +} From a00d0cc232e2c2248a6ce55d32d637eee27f5a25 Mon Sep 17 00:00:00 2001 From: Leoswaldo Macias Date: Tue, 2 Aug 2016 12:40:45 -0500 Subject: [PATCH 4/5] ciao-controller: add negative test cases for validation of invalid auth ciao-controller/compute_test.go was missing in its test coverage for all the scenarios for of failed authentication. These changes increases the code coverage for the previous common scenario. It was required to create new test cases which call the templates of its functionality but with invalid parameters for authentication and also needed to modify their templates so to stop evaluating the template because the following instructions would not apply to them if the invalid token scenario was provided. The new created negative test cases are: - TestCreateSingleServerInvalidToken - TestListServerDetailsTenantInvalidToken - TestShowServerDetailsInvalidToken - TestDeleteServerInvalidToken - TestServersActionStartInvalidToken - TestServerActionStopInvalidToken - TestListFlavorsInvalidToken - TestShowFlavorDetailsInvalidToken - TestListFlavorsDetailsInvalidToken - TestListTenantResourcesInvalidToken - TestListTenantQuotasInvalidToken - TestListNodeServersInvalidToken - TestListTenantsInvalidToken - TestListNodesInvalidToken - TestNodeSummaryInvalidToken - TestListCNCIsInvalidToken - TestListCNCIDetailsInvalidToken - TestListTracesInvalidToken - TestListEventsInvalidToken - TestClearEventsInvalidToken - TestTraceDataInvalidToken Fixes #349 Signed-off-by: Leoswaldo Macias --- ciao-controller/compute_test.go | 187 +++++++++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 3 deletions(-) diff --git a/ciao-controller/compute_test.go b/ciao-controller/compute_test.go index 94af72320..87ab46903 100644 --- a/ciao-controller/compute_test.go +++ b/ciao-controller/compute_test.go @@ -128,6 +128,36 @@ func TestCreateSingleServer(t *testing.T) { _ = testCreateServer(t, 1) } +func TestCreateSingleServerInvalidToken(t *testing.T) { + tenant, err := context.ds.GetTenant(testutil.ComputeUser) + if err != nil { + t.Fatal(err) + } + + // get a valid workload ID + wls, err := context.ds.GetWorkloads() + if err != nil { + t.Fatal(err) + } + + if len(wls) == 0 { + t.Fatal("No valid workloads") + } + + url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/servers" + + var server payloads.ComputeCreateServer + server.Server.MaxInstances = 1 + server.Server.Workload = wls[0].ID + + b, err := json.Marshal(server) + if err != nil { + t.Fatal(err) + } + + _ = testHTTPRequest(t, "POST", url, http.StatusUnauthorized, b, false) +} + func TestListServerDetailsTenant(t *testing.T) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { @@ -146,6 +176,21 @@ func TestListServerDetailsTenant(t *testing.T) { } } +func TestListServerDetailsTenantInvalidToken(t *testing.T) { + tenant, err := context.ds.GetTenant(testutil.ComputeUser) + if err != nil { + t.Fatal(err) + } + + servers := testCreateServer(t, 1) + if servers.TotalServers != 1 { + t.Fatal(err) + } + + url := testutil.ComputeURL + "/v2.1/" + tenant.ID + "/servers/detail" + _ = testHTTPRequest(t, "GET", url, http.StatusUnauthorized, nil, false) +} + func testListServerDetailsWorkload(t *testing.T, httpExpectedStatus int, validToken bool) { // get a valid workload ID wls, err := context.ds.GetWorkloads() @@ -204,6 +249,10 @@ func testShowServerDetails(t *testing.T, httpExpectedStatus int, validToken bool url := tURL + s1.ID body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var s2 payloads.ComputeServer err = json.Unmarshal(body, &s2) @@ -222,7 +271,11 @@ func TestShowServerDetails(t *testing.T) { testShowServerDetails(t, http.StatusOK, true) } -func testDeleteServer(t *testing.T, httpExpectedStatus int, validToken bool) { +func TestShowServerDetailsInvalidToken(t *testing.T) { + testShowServerDetails(t, http.StatusUnauthorized, false) +} + +func testDeleteServer(t *testing.T, httpExpectedStatus int, httpExpectedErrorStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -259,13 +312,17 @@ func testDeleteServer(t *testing.T, httpExpectedStatus int, validToken bool) { if s1.HostID != "" { _ = testHTTPRequest(t, "DELETE", url, httpExpectedStatus, nil, validToken) } else { - _ = testHTTPRequest(t, "DELETE", url, http.StatusInternalServerError, nil, validToken) + _ = testHTTPRequest(t, "DELETE", url, httpExpectedErrorStatus, nil, validToken) } } } func TestDeleteServer(t *testing.T) { - testDeleteServer(t, http.StatusAccepted, true) + testDeleteServer(t, http.StatusAccepted, http.StatusInternalServerError, true) +} + +func TestDeleteServerInvalidToken(t *testing.T) { + testDeleteServer(t, http.StatusUnauthorized, http.StatusUnauthorized, false) } func testServersActionStart(t *testing.T, httpExpectedStatus int, validToken bool) { @@ -324,6 +381,10 @@ func TestServersActionStart(t *testing.T) { testServersActionStart(t, http.StatusAccepted, true) } +func TestServersActionStartInvalidToken(t *testing.T) { + testServersActionStart(t, http.StatusUnauthorized, false) +} + func TestServersActionStop(t *testing.T) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { @@ -398,6 +459,10 @@ func TestServerActionStop(t *testing.T) { testServerActionStop(t, http.StatusAccepted, true) } +func TestServerActionStopInvalidToken(t *testing.T) { + testServerActionStop(t, http.StatusUnauthorized, false) +} + func TestServerActionStart(t *testing.T) { action := "os-start" @@ -459,6 +524,10 @@ func testListFlavors(t *testing.T, httpExpectedStatus int, data []byte, validTok } body := testHTTPRequest(t, "GET", url, httpExpectedStatus, data, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var flavors payloads.ComputeFlavors err = json.Unmarshal(body, &flavors) @@ -489,6 +558,10 @@ func TestListFlavors(t *testing.T) { testListFlavors(t, http.StatusOK, nil, true) } +func TestListFlavorsInvalidToken(t *testing.T) { + testListFlavors(t, http.StatusUnauthorized, nil, false) +} + func testShowFlavorDetails(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { @@ -522,6 +595,10 @@ func testShowFlavorDetails(t *testing.T, httpExpectedStatus int, validToken bool url := tURL + w.ID body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var f payloads.ComputeFlavorDetails @@ -540,6 +617,10 @@ func TestShowFlavorDetails(t *testing.T) { testShowFlavorDetails(t, http.StatusOK, true) } +func TestShowFlavorDetailsInvalidToken(t *testing.T) { + testShowFlavorDetails(t, http.StatusUnauthorized, false) +} + func testListFlavorsDetails(t *testing.T, httpExpectedStatus int, data []byte, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { @@ -554,6 +635,10 @@ func TestListFlavorsDetails(t *testing.T) { testListFlavorsDetails(t, http.StatusOK, nil, true) } +func TestListFlavorsDetailsInvalidToken(t *testing.T) { + testListFlavorsDetails(t, http.StatusUnauthorized, nil, false) +} + func testListTenantResources(t *testing.T, httpExpectedStatus int, validToken bool) { var usage payloads.CiaoUsageHistory @@ -579,6 +664,10 @@ func testListTenantResources(t *testing.T, httpExpectedStatus int, validToken bo tURL += v.Encode() body := testHTTPRequest(t, "GET", tURL, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoUsageHistory @@ -596,6 +685,10 @@ func TestListTenantResources(t *testing.T) { testListTenantResources(t, http.StatusOK, true) } +func TestListTenantResourcesInvalidToken(t *testing.T) { + testListTenantResources(t, http.StatusUnauthorized, false) +} + func testListTenantQuotas(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { @@ -629,6 +722,10 @@ func testListTenantQuotas(t *testing.T, httpExpectedStatus int, validToken bool) expected.ID = tenant.ID body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoTenantResources @@ -648,6 +745,10 @@ func TestListTenantQuotas(t *testing.T) { testListTenantQuotas(t, http.StatusOK, true) } +func TestListTenantQuotasInvalidToken(t *testing.T) { + testListTenantQuotas(t, http.StatusUnauthorized, false) +} + func testListEventsTenant(t *testing.T, httpExpectedStatus int, validToken bool) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { @@ -707,6 +808,10 @@ func testListNodeServers(t *testing.T, httpExpectedStatus int, validToken bool) url := testutil.ComputeURL + "/v2.1/nodes/" + n.ID + "/servers/detail" body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoServersStats @@ -729,6 +834,10 @@ func TestListNodeServers(t *testing.T) { testListNodeServers(t, http.StatusOK, true) } +func TestListNodeServersInvalidToken(t *testing.T) { + testListNodeServers(t, http.StatusUnauthorized, false) +} + func testListTenants(t *testing.T, httpExpectedStatus int, validToken bool) { tenants, err := context.ds.GetAllTenants() if err != nil { @@ -752,6 +861,10 @@ func testListTenants(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/tenants" body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoComputeTenants @@ -769,6 +882,10 @@ func TestListTenants(t *testing.T) { testListTenants(t, http.StatusOK, true) } +func TestListTenantsInvalidToken(t *testing.T) { + testListTenants(t, http.StatusUnauthorized, false) +} + func testListNodes(t *testing.T, httpExpectedStatus int, validToken bool) { expected := context.ds.GetNodeLastStats() @@ -796,6 +913,10 @@ func testListNodes(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/nodes" body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoComputeNodes @@ -817,6 +938,10 @@ func TestListNodes(t *testing.T) { testListNodes(t, http.StatusOK, true) } +func TestListNodesInvalidToken(t *testing.T) { + testListNodes(t, http.StatusUnauthorized, false) +} + func testNodeSummary(t *testing.T, httpExpectedStatus int, validToken bool) { var expected payloads.CiaoClusterStatus @@ -838,6 +963,10 @@ func testNodeSummary(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/nodes/summary" body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoClusterStatus @@ -855,6 +984,10 @@ func TestNodeSummary(t *testing.T) { testNodeSummary(t, http.StatusOK, true) } +func TestNodeSummaryInvalidToken(t *testing.T) { + testNodeSummary(t, http.StatusUnauthorized, false) +} + func testListCNCIs(t *testing.T, httpExpectedStatus int, validToken bool) { var expected payloads.CiaoCNCIs @@ -891,6 +1024,10 @@ func testListCNCIs(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/cncis" body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoCNCIs @@ -908,6 +1045,10 @@ func TestListCNCIs(t *testing.T) { testListCNCIs(t, http.StatusOK, true) } +func TestListCNCIsInvalidToken(t *testing.T) { + testListCNCIs(t, http.StatusUnauthorized, false) +} + func testListCNCIDetails(t *testing.T, httpExpectedStatus int, validToken bool) { cncis, err := context.ds.GetTenantCNCISummary("") if err != nil { @@ -945,6 +1086,10 @@ func testListCNCIDetails(t *testing.T, httpExpectedStatus int, validToken bool) url := testutil.ComputeURL + "/v2.1/cncis/" + cnci.InstanceID + "/detail" body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoCNCI @@ -963,6 +1108,10 @@ func TestListCNCIDetails(t *testing.T) { testListCNCIDetails(t, http.StatusOK, true) } +func TestListCNCIDetailsInvalidToken(t *testing.T) { + testListCNCIDetails(t, http.StatusUnauthorized, false) +} + func testListTraces(t *testing.T, httpExpectedStatus int, validToken bool) { var expected payloads.CiaoTracesSummary @@ -989,6 +1138,10 @@ func testListTraces(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/traces" body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoTracesSummary @@ -1006,6 +1159,10 @@ func TestListTraces(t *testing.T) { testListTraces(t, http.StatusOK, true) } +func TestListTracesInvalidToken(t *testing.T) { + testListTraces(t, http.StatusUnauthorized, false) +} + func testListEvents(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/events" @@ -1027,6 +1184,10 @@ func testListEvents(t *testing.T, httpExpectedStatus int, validToken bool) { } body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoEvents @@ -1044,10 +1205,18 @@ func TestListEvents(t *testing.T) { testListEvents(t, http.StatusOK, true) } +func TestListEventsInvalidToken(t *testing.T) { + testListEvents(t, http.StatusUnauthorized, false) +} + func testClearEvents(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/events" _ = testHTTPRequest(t, "DELETE", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } logs, err := context.ds.GetEventLog() if err != nil { @@ -1063,6 +1232,10 @@ func TestClearEvents(t *testing.T) { testClearEvents(t, http.StatusAccepted, true) } +func TestClearEventsInvalidToken(t *testing.T) { + testClearEvents(t, http.StatusUnauthorized, false) +} + func testTraceData(t *testing.T, httpExpectedStatus int, validToken bool) { client := testStartTracedWorkload(t) defer client.Ssntp.Close() @@ -1099,6 +1272,10 @@ func testTraceData(t *testing.T, httpExpectedStatus int, validToken bool) { url := testutil.ComputeURL + "/v2.1/traces/" + s.BatchID body := testHTTPRequest(t, "GET", url, httpExpectedStatus, nil, validToken) + // stop evaluating in case the scenario is InvalidToken + if httpExpectedStatus == 401 { + return + } var result payloads.CiaoTraceData @@ -1116,3 +1293,7 @@ func testTraceData(t *testing.T, httpExpectedStatus int, validToken bool) { func TestTraceData(t *testing.T) { testTraceData(t, http.StatusOK, true) } + +func TestTraceDataInvalidToken(t *testing.T) { + testTraceData(t, http.StatusUnauthorized, false) +} From 419fd8d930ebba63a3ef38eac32114fd4694108f Mon Sep 17 00:00:00 2001 From: Leoswaldo Macias Date: Tue, 2 Aug 2016 18:07:13 -0500 Subject: [PATCH 5/5] ciao-controller: add negative testcase for invalid tenantServersAction The function tenantServersAction has multiple scenarios (os-start, os-stop, os-delete) for multiple actions, but also verifies the requested action is valid, if not fail, this commit contains the required changes to to verify that, if the action is not valid, then verify it. To make this, we created the template testServersActionStop which receives two extra parameters, the expected http status and the action to perform In order to align the new code we had to made the TestServersActionStop to call it with the action "os-start" and its corresponding http status, and then we added a new test cases, TestServersActionStopWrongAction, which sends an invalid action, "wrong-action", with the correspoding http status (StatusServiceUnavailable). Fixes #349 Signed-off-by: Leoswaldo Macias --- ciao-controller/compute_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ciao-controller/compute_test.go b/ciao-controller/compute_test.go index 87ab46903..8d3328dac 100644 --- a/ciao-controller/compute_test.go +++ b/ciao-controller/compute_test.go @@ -385,7 +385,7 @@ func TestServersActionStartInvalidToken(t *testing.T) { testServersActionStart(t, http.StatusUnauthorized, false) } -func TestServersActionStop(t *testing.T) { +func testServersActionStop(t *testing.T, httpExpectedStatus int, action string) { tenant, err := context.ds.GetTenant(testutil.ComputeUser) if err != nil { t.Fatal(err) @@ -414,7 +414,7 @@ func TestServersActionStop(t *testing.T) { ids = append(ids, servers.Servers[0].ID) cmd := payloads.CiaoServersAction{ - Action: "os-stop", + Action: action, ServerIDs: ids, } @@ -423,7 +423,15 @@ func TestServersActionStop(t *testing.T) { t.Fatal(err) } - _ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b, true) + _ = testHTTPRequest(t, "POST", url, httpExpectedStatus, b, true) +} + +func TestServersActionStop(t *testing.T) { + testServersActionStop(t, http.StatusAccepted, "os-stop") +} + +func TestServersActionStopWrongAction(t *testing.T) { + testServersActionStop(t, http.StatusServiceUnavailable, "wrong-action") } func testServerActionStop(t *testing.T, httpExpectedStatus int, validToken bool) {