gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

extract_test.go (6742B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package ap_test
     19 
     20 import (
     21 	"context"
     22 	"encoding/json"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/activity/pub"
     26 	"github.com/superseriousbusiness/activity/streams"
     27 	"github.com/superseriousbusiness/activity/streams/vocab"
     28 	"github.com/superseriousbusiness/gotosocial/internal/ap"
     29 	"github.com/superseriousbusiness/gotosocial/testrig"
     30 )
     31 
     32 func document1() vocab.ActivityStreamsDocument {
     33 	d := streams.NewActivityStreamsDocument()
     34 
     35 	dMediaType := streams.NewActivityStreamsMediaTypeProperty()
     36 	dMediaType.Set("image/jpeg")
     37 	d.SetActivityStreamsMediaType(dMediaType)
     38 
     39 	dURL := streams.NewActivityStreamsUrlProperty()
     40 	dURL.AppendIRI(testrig.URLMustParse("https://s3-us-west-2.amazonaws.com/plushcity/media_attachments/files/106/867/380/219/163/828/original/88e8758c5f011439.jpg"))
     41 	d.SetActivityStreamsUrl(dURL)
     42 
     43 	dName := streams.NewActivityStreamsNameProperty()
     44 	dName.AppendXMLSchemaString("It's a cute plushie.")
     45 	d.SetActivityStreamsName(dName)
     46 
     47 	dBlurhash := streams.NewTootBlurhashProperty()
     48 	dBlurhash.Set("UxQ0EkRP_4tRxtRjWBt7%hozM_ayV@oLf6WB")
     49 	d.SetTootBlurhash(dBlurhash)
     50 
     51 	dSensitive := streams.NewActivityStreamsSensitiveProperty()
     52 	dSensitive.AppendXMLSchemaBoolean(true)
     53 	d.SetActivityStreamsSensitive(dSensitive)
     54 
     55 	return d
     56 }
     57 
     58 func attachment1() vocab.ActivityStreamsAttachmentProperty {
     59 	a := streams.NewActivityStreamsAttachmentProperty()
     60 	a.AppendActivityStreamsDocument(document1())
     61 	return a
     62 }
     63 
     64 func noteWithMentions1() vocab.ActivityStreamsNote {
     65 	note := streams.NewActivityStreamsNote()
     66 
     67 	tags := streams.NewActivityStreamsTagProperty()
     68 
     69 	mention1 := streams.NewActivityStreamsMention()
     70 
     71 	mention1Href := streams.NewActivityStreamsHrefProperty()
     72 	mention1Href.Set(testrig.URLMustParse("https://gts.superseriousbusiness.org/users/dumpsterqueer"))
     73 	mention1.SetActivityStreamsHref(mention1Href)
     74 
     75 	mention1Name := streams.NewActivityStreamsNameProperty()
     76 	mention1Name.AppendXMLSchemaString("@dumpsterqueer@superseriousbusiness.org")
     77 	mention1.SetActivityStreamsName(mention1Name)
     78 
     79 	mention2 := streams.NewActivityStreamsMention()
     80 
     81 	mention2Href := streams.NewActivityStreamsHrefProperty()
     82 	mention2Href.Set(testrig.URLMustParse("https://gts.superseriousbusiness.org/users/f0x"))
     83 	mention2.SetActivityStreamsHref(mention2Href)
     84 
     85 	mention2Name := streams.NewActivityStreamsNameProperty()
     86 	mention2Name.AppendXMLSchemaString("@f0x@superseriousbusiness.org")
     87 	mention2.SetActivityStreamsName(mention2Name)
     88 
     89 	tags.AppendActivityStreamsMention(mention1)
     90 	tags.AppendActivityStreamsMention(mention2)
     91 
     92 	note.SetActivityStreamsTag(tags)
     93 
     94 	content := streams.NewActivityStreamsContentProperty()
     95 	content.AppendXMLSchemaString("hey @f0x and @dumpsterqueer")
     96 	note.SetActivityStreamsContent(content)
     97 
     98 	return note
     99 }
    100 
    101 func addressable1() ap.Addressable {
    102 	// make a note addressed to public with followers in cc
    103 	note := streams.NewActivityStreamsNote()
    104 
    105 	toProp := streams.NewActivityStreamsToProperty()
    106 	toProp.AppendIRI(testrig.URLMustParse(pub.PublicActivityPubIRI))
    107 
    108 	note.SetActivityStreamsTo(toProp)
    109 
    110 	ccProp := streams.NewActivityStreamsCcProperty()
    111 	ccProp.AppendIRI(testrig.URLMustParse("http://localhost:8080/users/the_mighty_zork/followers"))
    112 
    113 	note.SetActivityStreamsCc(ccProp)
    114 
    115 	return note
    116 }
    117 
    118 func addressable2() ap.Addressable {
    119 	// make a note addressed to followers with public in cc
    120 	note := streams.NewActivityStreamsNote()
    121 
    122 	toProp := streams.NewActivityStreamsToProperty()
    123 	toProp.AppendIRI(testrig.URLMustParse("http://localhost:8080/users/the_mighty_zork/followers"))
    124 
    125 	note.SetActivityStreamsTo(toProp)
    126 
    127 	ccProp := streams.NewActivityStreamsCcProperty()
    128 	ccProp.AppendIRI(testrig.URLMustParse(pub.PublicActivityPubIRI))
    129 
    130 	note.SetActivityStreamsCc(ccProp)
    131 
    132 	return note
    133 }
    134 
    135 func addressable3() ap.Addressable {
    136 	// make a note addressed to followers
    137 	note := streams.NewActivityStreamsNote()
    138 
    139 	toProp := streams.NewActivityStreamsToProperty()
    140 	toProp.AppendIRI(testrig.URLMustParse("http://localhost:8080/users/the_mighty_zork/followers"))
    141 
    142 	note.SetActivityStreamsTo(toProp)
    143 
    144 	return note
    145 }
    146 
    147 func addressable4() vocab.ActivityStreamsAnnounce {
    148 	// https://github.com/superseriousbusiness/gotosocial/issues/267
    149 	announceJson := []byte(`
    150 {
    151 	"@context": "https://www.w3.org/ns/activitystreams",
    152 	"actor": "https://example.org/users/someone",
    153 	"cc": "https://another.instance/users/someone_else",
    154 	"id": "https://example.org/users/someone/statuses/107043888547829808/activity",
    155 	"object": "https://another.instance/users/someone_else/statuses/107026674805188668",
    156 	"published": "2021-10-04T15:08:35.00Z",
    157 	"to": "https://example.org/users/someone/followers",
    158 	"type": "Announce"
    159 }`)
    160 
    161 	var jsonAsMap map[string]interface{}
    162 	err := json.Unmarshal(announceJson, &jsonAsMap)
    163 	if err != nil {
    164 		panic(err)
    165 	}
    166 
    167 	t, err := streams.ToType(context.Background(), jsonAsMap)
    168 	if err != nil {
    169 		panic(err)
    170 	}
    171 
    172 	return t.(vocab.ActivityStreamsAnnounce)
    173 }
    174 
    175 func addressable5() ap.Addressable {
    176 	// make a note addressed to one person (direct message)
    177 	note := streams.NewActivityStreamsNote()
    178 
    179 	toProp := streams.NewActivityStreamsToProperty()
    180 	toProp.AppendIRI(testrig.URLMustParse("http://localhost:8080/users/1_happy_turtle"))
    181 
    182 	note.SetActivityStreamsTo(toProp)
    183 
    184 	return note
    185 }
    186 
    187 type ExtractTestSuite struct {
    188 	suite.Suite
    189 	document1         vocab.ActivityStreamsDocument
    190 	attachment1       vocab.ActivityStreamsAttachmentProperty
    191 	noteWithMentions1 vocab.ActivityStreamsNote
    192 	addressable1      ap.Addressable
    193 	addressable2      ap.Addressable
    194 	addressable3      ap.Addressable
    195 	addressable4      vocab.ActivityStreamsAnnounce
    196 	addressable5      ap.Addressable
    197 }
    198 
    199 func (suite *ExtractTestSuite) SetupTest() {
    200 	suite.document1 = document1()
    201 	suite.attachment1 = attachment1()
    202 	suite.noteWithMentions1 = noteWithMentions1()
    203 	suite.addressable1 = addressable1()
    204 	suite.addressable2 = addressable2()
    205 	suite.addressable3 = addressable3()
    206 	suite.addressable4 = addressable4()
    207 	suite.addressable5 = addressable5()
    208 }