Fix tests for invalid identifiers
This commit is contained in:
@@ -3,7 +3,6 @@ package proto_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -239,7 +238,6 @@ func TestSaveGetSettingsBundleWithNoSettings(t *testing.T) {
|
|||||||
cl := proto.NewBundleService("com.owncloud.api.settings", client)
|
cl := proto.NewBundleService("com.owncloud.api.settings", client)
|
||||||
|
|
||||||
cresponse, err := cl.SaveSettingsBundle(context.Background(), &createRequest)
|
cresponse, err := cl.SaveSettingsBundle(context.Background(), &createRequest)
|
||||||
fmt.Println(err)
|
|
||||||
if err != nil || (CustomError{} != testCase.expectedError) {
|
if err != nil || (CustomError{} != testCase.expectedError) {
|
||||||
var errorData CustomError
|
var errorData CustomError
|
||||||
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
||||||
@@ -592,7 +590,6 @@ func TestGetSettingsBundleCreatesFolder(t *testing.T) {
|
|||||||
_ = os.RemoveAll("ocis-settings-store")
|
_ = os.RemoveAll("ocis-settings-store")
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://github.com/owncloud/ocis-settings/issues/15
|
|
||||||
func TestGetSettingsBundleAccessOtherBundle(t *testing.T) {
|
func TestGetSettingsBundleAccessOtherBundle(t *testing.T) {
|
||||||
client := service.Client()
|
client := service.Client()
|
||||||
cl := proto.NewBundleService("com.owncloud.api.settings", client)
|
cl := proto.NewBundleService("com.owncloud.api.settings", client)
|
||||||
@@ -619,9 +616,14 @@ func TestGetSettingsBundleAccessOtherBundle(t *testing.T) {
|
|||||||
getRequest := proto.GetSettingsBundleRequest{Identifier: &bobIdentifier}
|
getRequest := proto.GetSettingsBundleRequest{Identifier: &bobIdentifier}
|
||||||
|
|
||||||
response, err := cl.GetSettingsBundle(context.Background(), &getRequest)
|
response, err := cl.GetSettingsBundle(context.Background(), &getRequest)
|
||||||
assert.NoError(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, response.SettingsBundle.Identifier.Extension, "alice-extension")
|
assert.Nil(t, response)
|
||||||
assert.Equal(t, response.SettingsBundle.Identifier.BundleKey, "alice-bundle")
|
var errorData CustomError
|
||||||
|
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
||||||
|
assert.Equal(t, "go.micro.client", errorData.ID)
|
||||||
|
assert.Equal(t, 500, errorData.Code)
|
||||||
|
assert.Equal(t, "extension: must be in a valid format.", errorData.Detail)
|
||||||
|
assert.Equal(t, "Internal Server Error", errorData.Status)
|
||||||
_ = os.RemoveAll("ocis-settings-store")
|
_ = os.RemoveAll("ocis-settings-store")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,18 +643,17 @@ func TestGetSettingsBundleWithInvalidIdentifier(t *testing.T) {
|
|||||||
var tests = []TestStruct{
|
var tests = []TestStruct{
|
||||||
{
|
{
|
||||||
"not existing",
|
"not existing",
|
||||||
"this key should not exist",
|
"this-key-should-not-exist",
|
||||||
"this key should not exist",
|
"this-key-should-not-exist",
|
||||||
"this.extension.should.not.exist",
|
"this-extension-should-not-exist",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{
|
CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "open ocis-settings-store/bundles/this.extension.should.not.exist/this key should not exist.json: no such file or directory",
|
Detail: "open ocis-settings-store/bundles/this-extension-should-not-exist/this-key-should-not-exist.json: no such file or directory",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
//https://github.com/owncloud/ocis-settings/issues/15
|
|
||||||
{
|
{
|
||||||
"bundle key in the root directory",
|
"bundle key in the root directory",
|
||||||
"/tmp/file",
|
"/tmp/file",
|
||||||
@@ -662,7 +663,7 @@ func TestGetSettingsBundleWithInvalidIdentifier(t *testing.T) {
|
|||||||
CustomError{
|
CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "open ocis-settings-store/bundles/simple-extension-name/tmp/file.json: no such file or directory",
|
Detail: "bundle_key: must be in a valid format.",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -675,7 +676,7 @@ func TestGetSettingsBundleWithInvalidIdentifier(t *testing.T) {
|
|||||||
CustomError{
|
CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "rpc error: code = InvalidArgument desc = Missing a required identifier attribute",
|
Detail: "bundle_key: cannot be blank.",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -688,7 +689,7 @@ func TestGetSettingsBundleWithInvalidIdentifier(t *testing.T) {
|
|||||||
CustomError{
|
CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "rpc error: code = InvalidArgument desc = Missing a required identifier attribute",
|
Detail: "extension: cannot be blank.",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -710,6 +711,7 @@ func TestGetSettingsBundleWithInvalidIdentifier(t *testing.T) {
|
|||||||
getResponse, err := cl.GetSettingsBundle(context.Background(), &getRequest)
|
getResponse, err := cl.GetSettingsBundle(context.Background(), &getRequest)
|
||||||
if err != nil || (CustomError{} != testCase.expectedError) {
|
if err != nil || (CustomError{} != testCase.expectedError) {
|
||||||
var errorData CustomError
|
var errorData CustomError
|
||||||
|
assert.Error(t, err)
|
||||||
assert.Empty(t, getResponse)
|
assert.Empty(t, getResponse)
|
||||||
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
||||||
assert.Equal(t, testCase.expectedError.ID, errorData.ID)
|
assert.Equal(t, testCase.expectedError.ID, errorData.ID)
|
||||||
@@ -732,7 +734,7 @@ func TestListMultipleSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -743,7 +745,7 @@ func TestListMultipleSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "bob's-bundle",
|
BundleKey: "bobs-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -754,7 +756,7 @@ func TestListMultipleSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "an-other-extension",
|
Extension: "an-other-extension",
|
||||||
BundleKey: "bob's-bundle",
|
BundleKey: "bobs-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -766,10 +768,10 @@ func TestListMultipleSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
response, err := cl.ListSettingsBundles(context.Background(), &listRequest)
|
response, err := cl.ListSettingsBundles(context.Background(), &listRequest)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, response.SettingsBundles[0].Identifier.Extension, "great-extension")
|
assert.Equal(t, response.SettingsBundles[0].Identifier.Extension, "great-extension")
|
||||||
assert.Equal(t, response.SettingsBundles[0].Identifier.BundleKey, "alice's-bundle")
|
assert.Equal(t, response.SettingsBundles[0].Identifier.BundleKey, "alices-bundle")
|
||||||
|
|
||||||
assert.Equal(t, response.SettingsBundles[1].Identifier.Extension, "great-extension")
|
assert.Equal(t, response.SettingsBundles[1].Identifier.Extension, "great-extension")
|
||||||
assert.Equal(t, response.SettingsBundles[1].Identifier.BundleKey, "bob's-bundle")
|
assert.Equal(t, response.SettingsBundles[1].Identifier.BundleKey, "bobs-bundle")
|
||||||
assert.Equal(t, 2, len(response.SettingsBundles))
|
assert.Equal(t, 2, len(response.SettingsBundles))
|
||||||
_ = os.RemoveAll("ocis-settings-store")
|
_ = os.RemoveAll("ocis-settings-store")
|
||||||
}
|
}
|
||||||
@@ -782,7 +784,7 @@ func TestListAllSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -793,7 +795,7 @@ func TestListAllSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "bob's-bundle",
|
BundleKey: "bobs-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -804,7 +806,7 @@ func TestListAllSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "an-other-extension",
|
Extension: "an-other-extension",
|
||||||
BundleKey: "bob's-bundle",
|
BundleKey: "bobs-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -816,13 +818,13 @@ func TestListAllSettingsBundlesOfSameExtension(t *testing.T) {
|
|||||||
response, err := cl.ListSettingsBundles(context.Background(), &listRequest)
|
response, err := cl.ListSettingsBundles(context.Background(), &listRequest)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, response.SettingsBundles[0].Identifier.Extension, "an-other-extension")
|
assert.Equal(t, response.SettingsBundles[0].Identifier.Extension, "an-other-extension")
|
||||||
assert.Equal(t, response.SettingsBundles[0].Identifier.BundleKey, "bob's-bundle")
|
assert.Equal(t, response.SettingsBundles[0].Identifier.BundleKey, "bobs-bundle")
|
||||||
|
|
||||||
assert.Equal(t, response.SettingsBundles[1].Identifier.Extension, "great-extension")
|
assert.Equal(t, response.SettingsBundles[1].Identifier.Extension, "great-extension")
|
||||||
assert.Equal(t, response.SettingsBundles[1].Identifier.BundleKey, "alice's-bundle")
|
assert.Equal(t, response.SettingsBundles[1].Identifier.BundleKey, "alices-bundle")
|
||||||
|
|
||||||
assert.Equal(t, response.SettingsBundles[2].Identifier.Extension, "great-extension")
|
assert.Equal(t, response.SettingsBundles[2].Identifier.Extension, "great-extension")
|
||||||
assert.Equal(t, response.SettingsBundles[2].Identifier.BundleKey, "bob's-bundle")
|
assert.Equal(t, response.SettingsBundles[2].Identifier.BundleKey, "bobs-bundle")
|
||||||
assert.Equal(t, 3, len(response.SettingsBundles))
|
assert.Equal(t, 3, len(response.SettingsBundles))
|
||||||
_ = os.RemoveAll("ocis-settings-store")
|
_ = os.RemoveAll("ocis-settings-store")
|
||||||
}
|
}
|
||||||
@@ -847,7 +849,7 @@ func TestListSettingsBundlesInFoldersThatAreNotAccessible(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -858,7 +860,7 @@ func TestListSettingsBundlesInFoldersThatAreNotAccessible(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "bob's-bundle",
|
BundleKey: "bobs-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -869,7 +871,7 @@ func TestListSettingsBundlesInFoldersThatAreNotAccessible(t *testing.T) {
|
|||||||
SettingsBundle: &proto.SettingsBundle{
|
SettingsBundle: &proto.SettingsBundle{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "an-other-extension",
|
Extension: "an-other-extension",
|
||||||
BundleKey: "bob's-bundle",
|
BundleKey: "bobs-bundle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -879,8 +881,14 @@ func TestListSettingsBundlesInFoldersThatAreNotAccessible(t *testing.T) {
|
|||||||
listRequest := proto.ListSettingsBundlesRequest{Identifier: &proto.Identifier{Extension: "../"}}
|
listRequest := proto.ListSettingsBundlesRequest{Identifier: &proto.Identifier{Extension: "../"}}
|
||||||
|
|
||||||
response, err := cl.ListSettingsBundles(context.Background(), &listRequest)
|
response, err := cl.ListSettingsBundles(context.Background(), &listRequest)
|
||||||
assert.NoError(t, err)
|
assert.Error(t, err)
|
||||||
assert.Empty(t, response.String())
|
assert.Nil(t, response)
|
||||||
|
var errorData CustomError
|
||||||
|
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
||||||
|
assert.Equal(t, "go.micro.client", errorData.ID)
|
||||||
|
assert.Equal(t, 500, errorData.Code)
|
||||||
|
assert.Equal(t, "extension: must be in a valid format.", errorData.Detail)
|
||||||
|
assert.Equal(t, "Internal Server Error", errorData.Status)
|
||||||
_ = os.RemoveAll("ocis-settings-store")
|
_ = os.RemoveAll("ocis-settings-store")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -897,7 +905,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "age",
|
SettingKey: "age",
|
||||||
},
|
},
|
||||||
@@ -909,7 +917,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "location",
|
SettingKey: "location",
|
||||||
},
|
},
|
||||||
@@ -921,7 +929,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "locked",
|
SettingKey: "locked",
|
||||||
},
|
},
|
||||||
@@ -933,7 +941,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "currencies",
|
SettingKey: "currencies",
|
||||||
},
|
},
|
||||||
@@ -953,7 +961,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "font-size",
|
SettingKey: "font-size",
|
||||||
},
|
},
|
||||||
@@ -974,9 +982,9 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "apple and peaches",
|
SettingKey: "apple-and-peaches",
|
||||||
},
|
},
|
||||||
Value: &proto.SettingsValue_ListValue{
|
Value: &proto.SettingsValue_ListValue{
|
||||||
ListValue: &proto.ListValue{
|
ListValue: &proto.ListValue{
|
||||||
@@ -993,7 +1001,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "",
|
Extension: "",
|
||||||
BundleKey: "alice's-bundle",
|
BundleKey: "alices-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "locked",
|
SettingKey: "locked",
|
||||||
},
|
},
|
||||||
@@ -1002,7 +1010,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
expectedError: CustomError{
|
expectedError: CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "rpc error: code = InvalidArgument desc = Missing a required identifier attribute",
|
Detail: "extension: cannot be blank.",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1020,7 +1028,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
expectedError: CustomError{
|
expectedError: CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "rpc error: code = InvalidArgument desc = Missing a required identifier attribute",
|
Detail: "bundle_key: cannot be blank.",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1029,7 +1037,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "bob's bundle",
|
BundleKey: "bobs-bundle",
|
||||||
AccountUuid: "",
|
AccountUuid: "",
|
||||||
SettingKey: "locked",
|
SettingKey: "locked",
|
||||||
},
|
},
|
||||||
@@ -1038,7 +1046,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
expectedError: CustomError{
|
expectedError: CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "rpc error: code = InvalidArgument desc = Missing a required identifier attribute",
|
Detail: "account_uuid: cannot be blank.",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1047,7 +1055,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "bob's bundle",
|
BundleKey: "bobs-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "",
|
SettingKey: "",
|
||||||
},
|
},
|
||||||
@@ -1056,48 +1064,63 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
expectedError: CustomError{
|
expectedError: CustomError{
|
||||||
ID: "go.micro.client",
|
ID: "go.micro.client",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "rpc error: code = InvalidArgument desc = Missing a required identifier attribute",
|
Detail: "setting_key: cannot be blank.",
|
||||||
Status: "Internal Server Error",
|
Status: "Internal Server Error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
//https://github.com/owncloud/ocis-settings/issues/15
|
|
||||||
testDataName: "../ in bundle key",
|
testDataName: "../ in bundle key",
|
||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "../bob's bundle",
|
BundleKey: "../bobs-bundle",
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "should-not-be-possible",
|
SettingKey: "should-not-be-possible",
|
||||||
},
|
},
|
||||||
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
||||||
},
|
},
|
||||||
|
expectedError: CustomError{
|
||||||
|
ID: "go.micro.client",
|
||||||
|
Code: 500,
|
||||||
|
Detail: "bundle_key: must be in a valid format.",
|
||||||
|
Status: "Internal Server Error",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
//https://github.com/owncloud/ocis-settings/issues/15
|
|
||||||
testDataName: "../ in account uuid",
|
testDataName: "../ in account uuid",
|
||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "great-extension",
|
Extension: "great-extension",
|
||||||
BundleKey: "bob's bundle",
|
BundleKey: "bobs-bundle",
|
||||||
AccountUuid: "../123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "../123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "should-not-be-possible",
|
SettingKey: "should-not-be-possible",
|
||||||
},
|
},
|
||||||
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
||||||
},
|
},
|
||||||
|
expectedError: CustomError{
|
||||||
|
ID: "go.micro.client",
|
||||||
|
Code: 500,
|
||||||
|
Detail: "account_uuid: must be a valid UUID.",
|
||||||
|
Status: "Internal Server Error",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
//https://github.com/owncloud/ocis-settings/issues/16
|
|
||||||
testDataName: "\\ in fields that are used to create folder and file names",
|
testDataName: "\\ in fields that are used to create folder and file names",
|
||||||
SettingsValue: proto.SettingsValue{
|
SettingsValue: proto.SettingsValue{
|
||||||
Identifier: &proto.Identifier{
|
Identifier: &proto.Identifier{
|
||||||
Extension: "\\-extension",
|
Extension: "\\-extension",
|
||||||
BundleKey: "\\ bundle",
|
BundleKey: "\\-bundle",
|
||||||
AccountUuid: "\\123e4567-e89b-12d3-a456-426652340000",
|
AccountUuid: "\\123e4567-e89b-12d3-a456-426652340000",
|
||||||
SettingKey: "should-not-be-possible",
|
SettingKey: "should-not-be-possible",
|
||||||
},
|
},
|
||||||
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
||||||
},
|
},
|
||||||
|
expectedError: CustomError{
|
||||||
|
ID: "go.micro.client",
|
||||||
|
Code: 500,
|
||||||
|
Detail: "account_uuid: must be a valid UUID; bundle_key: must be in a valid format; extension: must be in a valid format.",
|
||||||
|
Status: "Internal Server Error",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
client := service.Client()
|
client := service.Client()
|
||||||
@@ -1111,6 +1134,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
saveResponse, err := cl.SaveSettingsValue(context.Background(), &createRequest)
|
saveResponse, err := cl.SaveSettingsValue(context.Background(), &createRequest)
|
||||||
if err != nil || (CustomError{} != tests[index].expectedError) {
|
if err != nil || (CustomError{} != tests[index].expectedError) {
|
||||||
|
assert.Error(t, err)
|
||||||
var errorData CustomError
|
var errorData CustomError
|
||||||
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
||||||
assert.Equal(t, tests[index].expectedError.ID, errorData.ID)
|
assert.Equal(t, tests[index].expectedError.ID, errorData.ID)
|
||||||
@@ -1145,53 +1169,3 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//same as test above but List returns an empty array in case the extension name contains a `../`
|
|
||||||
//https://github.com/owncloud/ocis-settings/issues/15
|
|
||||||
func TestListSettingsValuesWithDotsInEntensionName(t *testing.T) {
|
|
||||||
type TestStruct struct {
|
|
||||||
testDataName string
|
|
||||||
SettingsValue proto.SettingsValue
|
|
||||||
}
|
|
||||||
|
|
||||||
var test = TestStruct{
|
|
||||||
testDataName: "../ in extension name",
|
|
||||||
SettingsValue: proto.SettingsValue{
|
|
||||||
Identifier: &proto.Identifier{
|
|
||||||
Extension: "../great-extension",
|
|
||||||
BundleKey: "bob's bundle",
|
|
||||||
AccountUuid: "123e4567-e89b-12d3-a456-426652340000",
|
|
||||||
SettingKey: "should-not-be-possible",
|
|
||||||
},
|
|
||||||
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
client := service.Client()
|
|
||||||
cl := proto.NewValueService("com.owncloud.api.settings", client)
|
|
||||||
|
|
||||||
expectedSetting, _ := json.Marshal(&test.SettingsValue)
|
|
||||||
createRequest := proto.SaveSettingsValueRequest{
|
|
||||||
SettingsValue: &test.SettingsValue,
|
|
||||||
}
|
|
||||||
saveResponse, err := cl.SaveSettingsValue(context.Background(), &createRequest)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
receivedSetting, _ := json.Marshal(saveResponse.SettingsValue)
|
|
||||||
assert.Equal(t, expectedSetting, receivedSetting)
|
|
||||||
|
|
||||||
getRequest := proto.GetSettingsValueRequest{
|
|
||||||
Identifier: test.SettingsValue.Identifier,
|
|
||||||
}
|
|
||||||
getResponse, err := cl.GetSettingsValue(context.Background(), &getRequest)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
receivedSetting, _ = json.Marshal(getResponse.SettingsValue)
|
|
||||||
assert.Equal(t, expectedSetting, receivedSetting)
|
|
||||||
|
|
||||||
listRequest := proto.ListSettingsValuesRequest{
|
|
||||||
Identifier: test.SettingsValue.Identifier,
|
|
||||||
}
|
|
||||||
listResponse, err := cl.ListSettingsValues(context.Background(), &listRequest)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, 0, len(listResponse.SettingsValues))
|
|
||||||
_ = os.RemoveAll("ocis-settings-store")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user