summaryrefslogtreecommitdiff
path: root/internal/api/util/mime_test.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-02-14 11:13:38 +0000
committerLibravatar tobi <tobi.smethurst@protonmail.com>2024-02-14 14:06:55 +0100
commitb9013a8ab352cf8fbfe07387bc1a291c240dd21f (patch)
tree96b10415c116975168ada554c5be7f181486ab0f /internal/api/util/mime_test.go
parent[bugfix] Don't return Account or Status if new and dereferencing failed, othe... (diff)
downloadgotosocial-b9013a8ab352cf8fbfe07387bc1a291c240dd21f.tar.xz
[bugfix] add stricter checks during all stages of dereferencing remote AS objects (#2639)
* add stricter checks during all stages of dereferencing remote AS objects * a comment
Diffstat (limited to 'internal/api/util/mime_test.go')
-rw-r--r--internal/api/util/mime_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/internal/api/util/mime_test.go b/internal/api/util/mime_test.go
new file mode 100644
index 000000000..6b12d1436
--- /dev/null
+++ b/internal/api/util/mime_test.go
@@ -0,0 +1,75 @@
+package util_test
+
+import (
+ "testing"
+
+ "github.com/superseriousbusiness/gotosocial/internal/api/util"
+)
+
+func TestIsASContentType(t *testing.T) {
+ for _, test := range []struct {
+ Input string
+ Expect bool
+ }{
+ {
+ Input: "application/activity+json",
+ Expect: true,
+ },
+ {
+ Input: "application/activity+json; charset=utf-8",
+ Expect: true,
+ },
+ {
+ Input: "application/activity+json;charset=utf-8",
+ Expect: true,
+ },
+ {
+ Input: "application/activity+json ;charset=utf-8",
+ Expect: true,
+ },
+ {
+ Input: "application/activity+json ; charset=utf-8",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json;profile=https://www.w3.org/ns/activitystreams",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json;profile=\"https://www.w3.org/ns/activitystreams\"",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json ;profile=https://www.w3.org/ns/activitystreams",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json ;profile=\"https://www.w3.org/ns/activitystreams\"",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json ; profile=https://www.w3.org/ns/activitystreams",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json ; profile=\"https://www.w3.org/ns/activitystreams\"",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json; profile=https://www.w3.org/ns/activitystreams",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
+ Expect: true,
+ },
+ {
+ Input: "application/ld+json",
+ Expect: false,
+ },
+ } {
+ if util.ASContentType(test.Input) != test.Expect {
+ t.Errorf("did not get expected result %v for input: %s", test.Expect, test.Input)
+ }
+ }
+}