summaryrefslogtreecommitdiffstats
path: root/modules/setting/setting_test.go
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2020-12-23 20:09:54 +0100
committerGitHub <noreply@github.com>2020-12-23 19:09:54 +0000
commitcd5278a44c45ad4f763b7142674c956576561d43 (patch)
tree66e62f583b58c03862f8cd5bd7d37668c69e12ca /modules/setting/setting_test.go
parente0c753e770a64cda5e3900aa1da3d7e1f3263c9a (diff)
downloadgitea-cd5278a44c45ad4f763b7142674c956576561d43.tar.gz
gitea-cd5278a44c45ad4f763b7142674c956576561d43.zip
Fix manifest encoding (#14114)
The previous URL encoding would encode spaces to '+' for the app name which is incorrect. Use base64 encoding instead which does not have such issues.
Diffstat (limited to 'modules/setting/setting_test.go')
-rw-r--r--modules/setting/setting_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/setting/setting_test.go b/modules/setting/setting_test.go
new file mode 100644
index 0000000000..f12fd8843a
--- /dev/null
+++ b/modules/setting/setting_test.go
@@ -0,0 +1,29 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package setting
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestMakeAbsoluteAssetURL(t *testing.T) {
+ assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234", "https://localhost:2345"))
+ assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234/", "https://localhost:2345"))
+ assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234/", "https://localhost:2345/"))
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234", "/foo"))
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/", "/foo"))
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/", "/foo/"))
+ assert.Equal(t, "https://localhost:1234/foo/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo", "/bar"))
+ assert.Equal(t, "https://localhost:1234/foo/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/bar"))
+ assert.Equal(t, "https://localhost:1234/foo/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/bar/"))
+}
+
+func TestMakeManifestData(t *testing.T) {
+ jsonBytes := MakeManifestData(`Example App '\"`, "https://example.com", "https://example.com/foo/bar")
+ assert.True(t, json.Valid(jsonBytes))
+}