From a81cc71ec5ae0ab3641212c960dbc55d0ac87d10 Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Thu, 1 Oct 2020 10:39:24 +0545 Subject: [PATCH] [Tests-Only] ocs http tests for config and capabilities endpoints --- ocs/pkg/server/http/svc_test.go | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 5dc429038a..c05473d652 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -170,6 +170,21 @@ type GetUsersGroupsResponse struct { } `json:"ocs" xml:"ocs"` } +type OcsConfig struct { + Version string `json:"version" xml:"version"` + Website string `json:"website" xml:"website"` + Host string `json:"host" xml:"host"` + Contact string `json:"contact" xml:"contact"` + Ssl string `json:"ssl" xml:"ssl"` +} + +type GetConfigResponse struct { + Ocs struct { + Meta Meta `json:"meta" xml:"meta"` + Data OcsConfig `json:"data" xml:"data"` + } `json:"ocs" xml:"ocs"` +} + func assertStatusCode(t *testing.T, statusCode int, res *httptest.ResponseRecorder, ocsVersion string) { if ocsVersion == "v1.php" { assert.Equal(t, 200, res.Code) @@ -1672,3 +1687,76 @@ func TestRemoveUserFromGroup(t *testing.T) { } } } + +// Issue: https://github.com/owncloud/ocis-ocs/issues/59 - cloud/capabilities endpoint not implemented +func TestCapablilities(t *testing.T) { + for _, ocsVersion := range ocsVersions { + for _, format := range formats { + formatpart := getFormatString(format) + res, err := sendRequest( + "GET", + fmt.Sprintf("/%s/cloud/capabilities%s", ocsVersion, formatpart), + "", + "admin:admin", + ) + + if err != nil { + t.Fatal(err) + } + + var response EmptyResponse + if format == "json" { + if err := json.Unmarshal(res.Body.Bytes(), &response); err != nil { + t.Fatal(err) + } + } else { + if err := xml.Unmarshal(res.Body.Bytes(), &response.Ocs); err != nil { + t.Fatal(err) + } + } + + assertStatusCode(t, 404, res, ocsVersion) + assertResponseMeta(t, Meta{ + "error", + 998, + "not found", + }, response.Ocs.Meta) + assert.Empty(t, response.Ocs.Data) + } + } +} + +func TestGetConfig(t *testing.T) { + for _, ocsVersion := range ocsVersions { + for _, format := range formats { + formatpart := getFormatString(format) + res, err := sendRequest( + "GET", + fmt.Sprintf("/%s/config%s", ocsVersion, formatpart), + "", + "admin:admin", + ) + + if err != nil { + t.Fatal(err) + } + + var response GetConfigResponse + if format == "json" { + if err := json.Unmarshal(res.Body.Bytes(), &response); err != nil { + t.Fatal(err) + } + } else { + if err := xml.Unmarshal(res.Body.Bytes(), &response.Ocs); err != nil { + t.Fatal(err) + } + } + + assertStatusCode(t, 200, res, ocsVersion) + assert.True(t, response.Ocs.Meta.Success(ocsVersion), "The response was expected to be successful but failed") + assert.Equal(t, OcsConfig{ + "1.7", "ocis", "", "", "true", + }, response.Ocs.Data) + } + } +} \ No newline at end of file