reportsget_test.go (35251B)
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 admin_test 19 20 import ( 21 "encoding/json" 22 "fmt" 23 "io/ioutil" 24 "net/http" 25 "net/http/httptest" 26 "strconv" 27 "testing" 28 29 "github.com/stretchr/testify/suite" 30 "github.com/superseriousbusiness/gotosocial/internal/api/client/admin" 31 apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" 32 "github.com/superseriousbusiness/gotosocial/internal/config" 33 "github.com/superseriousbusiness/gotosocial/internal/gtserror" 34 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 35 "github.com/superseriousbusiness/gotosocial/internal/oauth" 36 "github.com/superseriousbusiness/gotosocial/testrig" 37 ) 38 39 type ReportsGetTestSuite struct { 40 AdminStandardTestSuite 41 } 42 43 func (suite *ReportsGetTestSuite) getReports( 44 account *gtsmodel.Account, 45 token *gtsmodel.Token, 46 user *gtsmodel.User, 47 expectedHTTPStatus int, 48 expectedBody string, 49 resolved *bool, 50 accountID string, 51 targetAccountID string, 52 maxID string, 53 sinceID string, 54 minID string, 55 limit int, 56 ) ([]*apimodel.AdminReport, string, error) { 57 // instantiate recorder + test context 58 recorder := httptest.NewRecorder() 59 ctx, _ := testrig.CreateGinTestContext(recorder, nil) 60 ctx.Set(oauth.SessionAuthorizedAccount, account) 61 ctx.Set(oauth.SessionAuthorizedToken, oauth.DBTokenToToken(token)) 62 ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"]) 63 ctx.Set(oauth.SessionAuthorizedUser, user) 64 65 // create the request URI 66 requestPath := admin.ReportsPath + "?" + admin.LimitKey + "=" + strconv.Itoa(limit) 67 if resolved != nil { 68 requestPath = requestPath + "&" + admin.ResolvedKey + "=" + strconv.FormatBool(*resolved) 69 } 70 if accountID != "" { 71 requestPath = requestPath + "&" + admin.AccountIDKey + "=" + accountID 72 } 73 if targetAccountID != "" { 74 requestPath = requestPath + "&" + admin.TargetAccountIDKey + "=" + targetAccountID 75 } 76 if maxID != "" { 77 requestPath = requestPath + "&" + admin.MaxIDKey + "=" + maxID 78 } 79 if sinceID != "" { 80 requestPath = requestPath + "&" + admin.SinceIDKey + "=" + sinceID 81 } 82 if minID != "" { 83 requestPath = requestPath + "&" + admin.MinIDKey + "=" + minID 84 } 85 baseURI := config.GetProtocol() + "://" + config.GetHost() 86 requestURI := baseURI + "/api/" + requestPath 87 88 // create the request 89 ctx.Request = httptest.NewRequest(http.MethodGet, requestURI, nil) 90 ctx.Request.Header.Set("accept", "application/json") 91 92 // trigger the handler 93 suite.adminModule.ReportsGETHandler(ctx) 94 95 // read the response 96 result := recorder.Result() 97 defer result.Body.Close() 98 99 b, err := ioutil.ReadAll(result.Body) 100 if err != nil { 101 return nil, "", err 102 } 103 104 errs := gtserror.MultiError{} 105 106 if resultCode := recorder.Code; expectedHTTPStatus != resultCode { 107 errs = append(errs, fmt.Sprintf("expected %d got %d", expectedHTTPStatus, resultCode)) 108 } 109 110 // if we got an expected body, return early 111 if expectedBody != "" { 112 if string(b) != expectedBody { 113 errs = append(errs, fmt.Sprintf("expected %s got %s", expectedBody, string(b))) 114 } 115 return nil, "", errs.Combine() 116 } 117 118 resp := []*apimodel.AdminReport{} 119 if err := json.Unmarshal(b, &resp); err != nil { 120 return nil, "", err 121 } 122 123 return resp, result.Header.Get("Link"), nil 124 } 125 126 func (suite *ReportsGetTestSuite) TestReportsGetAll() { 127 testAccount := suite.testAccounts["admin_account"] 128 testToken := suite.testTokens["admin_account"] 129 testUser := suite.testUsers["admin_account"] 130 131 reports, link, err := suite.getReports(testAccount, testToken, testUser, http.StatusOK, "", nil, "", "", "", "", "", 20) 132 suite.NoError(err) 133 suite.NotEmpty(reports) 134 135 b, err := json.MarshalIndent(&reports, "", " ") 136 suite.NoError(err) 137 138 suite.Equal(`[ 139 { 140 "id": "01GP3DFY9XQ1TJMZT5BGAZPXX7", 141 "action_taken": true, 142 "action_taken_at": "2022-05-15T15:01:56.000Z", 143 "category": "other", 144 "comment": "this is a turtle, not a person, therefore should not be a poster", 145 "forwarded": true, 146 "created_at": "2022-05-15T14:20:12.000Z", 147 "updated_at": "2022-05-15T14:20:12.000Z", 148 "account": { 149 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 150 "username": "foss_satan", 151 "domain": "fossbros-anonymous.io", 152 "created_at": "2021-09-26T10:52:36.000Z", 153 "email": "", 154 "ip": null, 155 "ips": [], 156 "locale": "", 157 "invite_request": null, 158 "role": { 159 "name": "user" 160 }, 161 "confirmed": false, 162 "approved": false, 163 "disabled": false, 164 "silenced": false, 165 "suspended": false, 166 "account": { 167 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 168 "username": "foss_satan", 169 "acct": "foss_satan@fossbros-anonymous.io", 170 "display_name": "big gerald", 171 "locked": false, 172 "discoverable": true, 173 "bot": false, 174 "created_at": "2021-09-26T10:52:36.000Z", 175 "note": "i post about like, i dunno, stuff, or whatever!!!!", 176 "url": "http://fossbros-anonymous.io/@foss_satan", 177 "avatar": "", 178 "avatar_static": "", 179 "header": "http://localhost:8080/assets/default_header.png", 180 "header_static": "http://localhost:8080/assets/default_header.png", 181 "followers_count": 0, 182 "following_count": 0, 183 "statuses_count": 1, 184 "last_status_at": "2021-09-20T10:40:37.000Z", 185 "emojis": [], 186 "fields": [] 187 } 188 }, 189 "target_account": { 190 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 191 "username": "1happyturtle", 192 "domain": null, 193 "created_at": "2022-06-04T13:12:00.000Z", 194 "email": "tortle.dude@example.org", 195 "ip": "118.44.18.196", 196 "ips": [], 197 "locale": "en", 198 "invite_request": null, 199 "role": { 200 "name": "user" 201 }, 202 "confirmed": true, 203 "approved": true, 204 "disabled": false, 205 "silenced": false, 206 "suspended": false, 207 "account": { 208 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 209 "username": "1happyturtle", 210 "acct": "1happyturtle", 211 "display_name": "happy little turtle :3", 212 "locked": true, 213 "discoverable": false, 214 "bot": false, 215 "created_at": "2022-06-04T13:12:00.000Z", 216 "note": "\u003cp\u003ei post about things that concern me\u003c/p\u003e", 217 "url": "http://localhost:8080/@1happyturtle", 218 "avatar": "", 219 "avatar_static": "", 220 "header": "http://localhost:8080/assets/default_header.png", 221 "header_static": "http://localhost:8080/assets/default_header.png", 222 "followers_count": 1, 223 "following_count": 1, 224 "statuses_count": 7, 225 "last_status_at": "2021-10-20T10:40:37.000Z", 226 "emojis": [], 227 "fields": [ 228 { 229 "name": "should you follow me?", 230 "value": "maybe!", 231 "verified_at": null 232 }, 233 { 234 "name": "age", 235 "value": "120", 236 "verified_at": null 237 } 238 ], 239 "role": { 240 "name": "user" 241 } 242 }, 243 "created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG" 244 }, 245 "assigned_account": { 246 "id": "01F8MH17FWEB39HZJ76B6VXSKF", 247 "username": "admin", 248 "domain": null, 249 "created_at": "2022-05-17T13:10:59.000Z", 250 "email": "admin@example.org", 251 "ip": "89.122.255.1", 252 "ips": [], 253 "locale": "en", 254 "invite_request": null, 255 "role": { 256 "name": "admin" 257 }, 258 "confirmed": true, 259 "approved": true, 260 "disabled": false, 261 "silenced": false, 262 "suspended": false, 263 "account": { 264 "id": "01F8MH17FWEB39HZJ76B6VXSKF", 265 "username": "admin", 266 "acct": "admin", 267 "display_name": "", 268 "locked": false, 269 "discoverable": true, 270 "bot": false, 271 "created_at": "2022-05-17T13:10:59.000Z", 272 "note": "", 273 "url": "http://localhost:8080/@admin", 274 "avatar": "", 275 "avatar_static": "", 276 "header": "http://localhost:8080/assets/default_header.png", 277 "header_static": "http://localhost:8080/assets/default_header.png", 278 "followers_count": 1, 279 "following_count": 1, 280 "statuses_count": 4, 281 "last_status_at": "2021-10-20T10:41:37.000Z", 282 "emojis": [], 283 "fields": [], 284 "enable_rss": true, 285 "role": { 286 "name": "admin" 287 } 288 }, 289 "created_by_application_id": "01F8MGXQRHYF5QPMTMXP78QC2F" 290 }, 291 "action_taken_by_account": { 292 "id": "01F8MH17FWEB39HZJ76B6VXSKF", 293 "username": "admin", 294 "domain": null, 295 "created_at": "2022-05-17T13:10:59.000Z", 296 "email": "admin@example.org", 297 "ip": "89.122.255.1", 298 "ips": [], 299 "locale": "en", 300 "invite_request": null, 301 "role": { 302 "name": "admin" 303 }, 304 "confirmed": true, 305 "approved": true, 306 "disabled": false, 307 "silenced": false, 308 "suspended": false, 309 "account": { 310 "id": "01F8MH17FWEB39HZJ76B6VXSKF", 311 "username": "admin", 312 "acct": "admin", 313 "display_name": "", 314 "locked": false, 315 "discoverable": true, 316 "bot": false, 317 "created_at": "2022-05-17T13:10:59.000Z", 318 "note": "", 319 "url": "http://localhost:8080/@admin", 320 "avatar": "", 321 "avatar_static": "", 322 "header": "http://localhost:8080/assets/default_header.png", 323 "header_static": "http://localhost:8080/assets/default_header.png", 324 "followers_count": 1, 325 "following_count": 1, 326 "statuses_count": 4, 327 "last_status_at": "2021-10-20T10:41:37.000Z", 328 "emojis": [], 329 "fields": [], 330 "enable_rss": true, 331 "role": { 332 "name": "admin" 333 } 334 }, 335 "created_by_application_id": "01F8MGXQRHYF5QPMTMXP78QC2F" 336 }, 337 "statuses": [], 338 "rule_ids": [], 339 "action_taken_comment": "user was warned not to be a turtle anymore" 340 }, 341 { 342 "id": "01GP3AWY4CRDVRNZKW0TEAMB5R", 343 "action_taken": false, 344 "action_taken_at": null, 345 "category": "other", 346 "comment": "dark souls sucks, please yeet this nerd", 347 "forwarded": true, 348 "created_at": "2022-05-14T10:20:03.000Z", 349 "updated_at": "2022-05-14T10:20:03.000Z", 350 "account": { 351 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 352 "username": "1happyturtle", 353 "domain": null, 354 "created_at": "2022-06-04T13:12:00.000Z", 355 "email": "tortle.dude@example.org", 356 "ip": "118.44.18.196", 357 "ips": [], 358 "locale": "en", 359 "invite_request": null, 360 "role": { 361 "name": "user" 362 }, 363 "confirmed": true, 364 "approved": true, 365 "disabled": false, 366 "silenced": false, 367 "suspended": false, 368 "account": { 369 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 370 "username": "1happyturtle", 371 "acct": "1happyturtle", 372 "display_name": "happy little turtle :3", 373 "locked": true, 374 "discoverable": false, 375 "bot": false, 376 "created_at": "2022-06-04T13:12:00.000Z", 377 "note": "\u003cp\u003ei post about things that concern me\u003c/p\u003e", 378 "url": "http://localhost:8080/@1happyturtle", 379 "avatar": "", 380 "avatar_static": "", 381 "header": "http://localhost:8080/assets/default_header.png", 382 "header_static": "http://localhost:8080/assets/default_header.png", 383 "followers_count": 1, 384 "following_count": 1, 385 "statuses_count": 7, 386 "last_status_at": "2021-10-20T10:40:37.000Z", 387 "emojis": [], 388 "fields": [ 389 { 390 "name": "should you follow me?", 391 "value": "maybe!", 392 "verified_at": null 393 }, 394 { 395 "name": "age", 396 "value": "120", 397 "verified_at": null 398 } 399 ], 400 "role": { 401 "name": "user" 402 } 403 }, 404 "created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG" 405 }, 406 "target_account": { 407 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 408 "username": "foss_satan", 409 "domain": "fossbros-anonymous.io", 410 "created_at": "2021-09-26T10:52:36.000Z", 411 "email": "", 412 "ip": null, 413 "ips": [], 414 "locale": "", 415 "invite_request": null, 416 "role": { 417 "name": "user" 418 }, 419 "confirmed": false, 420 "approved": false, 421 "disabled": false, 422 "silenced": false, 423 "suspended": false, 424 "account": { 425 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 426 "username": "foss_satan", 427 "acct": "foss_satan@fossbros-anonymous.io", 428 "display_name": "big gerald", 429 "locked": false, 430 "discoverable": true, 431 "bot": false, 432 "created_at": "2021-09-26T10:52:36.000Z", 433 "note": "i post about like, i dunno, stuff, or whatever!!!!", 434 "url": "http://fossbros-anonymous.io/@foss_satan", 435 "avatar": "", 436 "avatar_static": "", 437 "header": "http://localhost:8080/assets/default_header.png", 438 "header_static": "http://localhost:8080/assets/default_header.png", 439 "followers_count": 0, 440 "following_count": 0, 441 "statuses_count": 1, 442 "last_status_at": "2021-09-20T10:40:37.000Z", 443 "emojis": [], 444 "fields": [] 445 } 446 }, 447 "assigned_account": null, 448 "action_taken_by_account": null, 449 "statuses": [ 450 { 451 "id": "01FVW7JHQFSFK166WWKR8CBA6M", 452 "created_at": "2021-09-20T10:40:37.000Z", 453 "in_reply_to_id": null, 454 "in_reply_to_account_id": null, 455 "sensitive": false, 456 "spoiler_text": "", 457 "visibility": "unlisted", 458 "language": "en", 459 "uri": "http://fossbros-anonymous.io/users/foss_satan/statuses/01FVW7JHQFSFK166WWKR8CBA6M", 460 "url": "http://fossbros-anonymous.io/@foss_satan/statuses/01FVW7JHQFSFK166WWKR8CBA6M", 461 "replies_count": 0, 462 "reblogs_count": 0, 463 "favourites_count": 0, 464 "favourited": false, 465 "reblogged": false, 466 "muted": false, 467 "bookmarked": false, 468 "pinned": false, 469 "content": "dark souls status bot: \"thoughts of dog\"", 470 "reblog": null, 471 "account": { 472 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 473 "username": "foss_satan", 474 "acct": "foss_satan@fossbros-anonymous.io", 475 "display_name": "big gerald", 476 "locked": false, 477 "discoverable": true, 478 "bot": false, 479 "created_at": "2021-09-26T10:52:36.000Z", 480 "note": "i post about like, i dunno, stuff, or whatever!!!!", 481 "url": "http://fossbros-anonymous.io/@foss_satan", 482 "avatar": "", 483 "avatar_static": "", 484 "header": "http://localhost:8080/assets/default_header.png", 485 "header_static": "http://localhost:8080/assets/default_header.png", 486 "followers_count": 0, 487 "following_count": 0, 488 "statuses_count": 1, 489 "last_status_at": "2021-09-20T10:40:37.000Z", 490 "emojis": [], 491 "fields": [] 492 }, 493 "media_attachments": [ 494 { 495 "id": "01FVW7RXPQ8YJHTEXYPE7Q8ZY0", 496 "type": "image", 497 "url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/original/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 498 "text_url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/original/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 499 "preview_url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/small/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 500 "remote_url": "http://fossbros-anonymous.io/attachments/original/13bbc3f8-2b5e-46ea-9531-40b4974d9912.jpg", 501 "preview_remote_url": "http://fossbros-anonymous.io/attachments/small/a499f55b-2d1e-4acd-98d2-1ac2ba6d79b9.jpg", 502 "meta": { 503 "original": { 504 "width": 472, 505 "height": 291, 506 "size": "472x291", 507 "aspect": 1.6219932 508 }, 509 "small": { 510 "width": 472, 511 "height": 291, 512 "size": "472x291", 513 "aspect": 1.6219932 514 }, 515 "focus": { 516 "x": 0, 517 "y": 0 518 } 519 }, 520 "description": "tweet from thoughts of dog: i drank. all the water. in my bowl. earlier. but just now. i returned. to the same bowl. and it was. full again.. the bowl. is haunted", 521 "blurhash": "LARysgM_IU_3~pD%M_Rj_39FIAt6" 522 } 523 ], 524 "mentions": [], 525 "tags": [], 526 "emojis": [], 527 "card": null, 528 "poll": null 529 } 530 ], 531 "rule_ids": [], 532 "action_taken_comment": null 533 } 534 ]`, string(b)) 535 536 suite.Equal(`<http://localhost:8080/api/v1/admin/reports?limit=20&max_id=01GP3AWY4CRDVRNZKW0TEAMB5R>; rel="next", <http://localhost:8080/api/v1/admin/reports?limit=20&min_id=01GP3DFY9XQ1TJMZT5BGAZPXX7>; rel="prev"`, link) 537 } 538 539 func (suite *ReportsGetTestSuite) TestReportsGetCreatedByAccount() { 540 testAccount := suite.testAccounts["admin_account"] 541 testToken := suite.testTokens["admin_account"] 542 testUser := suite.testUsers["admin_account"] 543 account := suite.testAccounts["local_account_2"] 544 545 reports, link, err := suite.getReports(testAccount, testToken, testUser, http.StatusOK, "", nil, account.ID, "", "", "", "", 20) 546 suite.NoError(err) 547 suite.NotEmpty(reports) 548 549 b, err := json.MarshalIndent(&reports, "", " ") 550 suite.NoError(err) 551 552 suite.Equal(`[ 553 { 554 "id": "01GP3AWY4CRDVRNZKW0TEAMB5R", 555 "action_taken": false, 556 "action_taken_at": null, 557 "category": "other", 558 "comment": "dark souls sucks, please yeet this nerd", 559 "forwarded": true, 560 "created_at": "2022-05-14T10:20:03.000Z", 561 "updated_at": "2022-05-14T10:20:03.000Z", 562 "account": { 563 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 564 "username": "1happyturtle", 565 "domain": null, 566 "created_at": "2022-06-04T13:12:00.000Z", 567 "email": "tortle.dude@example.org", 568 "ip": "118.44.18.196", 569 "ips": [], 570 "locale": "en", 571 "invite_request": null, 572 "role": { 573 "name": "user" 574 }, 575 "confirmed": true, 576 "approved": true, 577 "disabled": false, 578 "silenced": false, 579 "suspended": false, 580 "account": { 581 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 582 "username": "1happyturtle", 583 "acct": "1happyturtle", 584 "display_name": "happy little turtle :3", 585 "locked": true, 586 "discoverable": false, 587 "bot": false, 588 "created_at": "2022-06-04T13:12:00.000Z", 589 "note": "\u003cp\u003ei post about things that concern me\u003c/p\u003e", 590 "url": "http://localhost:8080/@1happyturtle", 591 "avatar": "", 592 "avatar_static": "", 593 "header": "http://localhost:8080/assets/default_header.png", 594 "header_static": "http://localhost:8080/assets/default_header.png", 595 "followers_count": 1, 596 "following_count": 1, 597 "statuses_count": 7, 598 "last_status_at": "2021-10-20T10:40:37.000Z", 599 "emojis": [], 600 "fields": [ 601 { 602 "name": "should you follow me?", 603 "value": "maybe!", 604 "verified_at": null 605 }, 606 { 607 "name": "age", 608 "value": "120", 609 "verified_at": null 610 } 611 ], 612 "role": { 613 "name": "user" 614 } 615 }, 616 "created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG" 617 }, 618 "target_account": { 619 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 620 "username": "foss_satan", 621 "domain": "fossbros-anonymous.io", 622 "created_at": "2021-09-26T10:52:36.000Z", 623 "email": "", 624 "ip": null, 625 "ips": [], 626 "locale": "", 627 "invite_request": null, 628 "role": { 629 "name": "user" 630 }, 631 "confirmed": false, 632 "approved": false, 633 "disabled": false, 634 "silenced": false, 635 "suspended": false, 636 "account": { 637 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 638 "username": "foss_satan", 639 "acct": "foss_satan@fossbros-anonymous.io", 640 "display_name": "big gerald", 641 "locked": false, 642 "discoverable": true, 643 "bot": false, 644 "created_at": "2021-09-26T10:52:36.000Z", 645 "note": "i post about like, i dunno, stuff, or whatever!!!!", 646 "url": "http://fossbros-anonymous.io/@foss_satan", 647 "avatar": "", 648 "avatar_static": "", 649 "header": "http://localhost:8080/assets/default_header.png", 650 "header_static": "http://localhost:8080/assets/default_header.png", 651 "followers_count": 0, 652 "following_count": 0, 653 "statuses_count": 1, 654 "last_status_at": "2021-09-20T10:40:37.000Z", 655 "emojis": [], 656 "fields": [] 657 } 658 }, 659 "assigned_account": null, 660 "action_taken_by_account": null, 661 "statuses": [ 662 { 663 "id": "01FVW7JHQFSFK166WWKR8CBA6M", 664 "created_at": "2021-09-20T10:40:37.000Z", 665 "in_reply_to_id": null, 666 "in_reply_to_account_id": null, 667 "sensitive": false, 668 "spoiler_text": "", 669 "visibility": "unlisted", 670 "language": "en", 671 "uri": "http://fossbros-anonymous.io/users/foss_satan/statuses/01FVW7JHQFSFK166WWKR8CBA6M", 672 "url": "http://fossbros-anonymous.io/@foss_satan/statuses/01FVW7JHQFSFK166WWKR8CBA6M", 673 "replies_count": 0, 674 "reblogs_count": 0, 675 "favourites_count": 0, 676 "favourited": false, 677 "reblogged": false, 678 "muted": false, 679 "bookmarked": false, 680 "pinned": false, 681 "content": "dark souls status bot: \"thoughts of dog\"", 682 "reblog": null, 683 "account": { 684 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 685 "username": "foss_satan", 686 "acct": "foss_satan@fossbros-anonymous.io", 687 "display_name": "big gerald", 688 "locked": false, 689 "discoverable": true, 690 "bot": false, 691 "created_at": "2021-09-26T10:52:36.000Z", 692 "note": "i post about like, i dunno, stuff, or whatever!!!!", 693 "url": "http://fossbros-anonymous.io/@foss_satan", 694 "avatar": "", 695 "avatar_static": "", 696 "header": "http://localhost:8080/assets/default_header.png", 697 "header_static": "http://localhost:8080/assets/default_header.png", 698 "followers_count": 0, 699 "following_count": 0, 700 "statuses_count": 1, 701 "last_status_at": "2021-09-20T10:40:37.000Z", 702 "emojis": [], 703 "fields": [] 704 }, 705 "media_attachments": [ 706 { 707 "id": "01FVW7RXPQ8YJHTEXYPE7Q8ZY0", 708 "type": "image", 709 "url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/original/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 710 "text_url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/original/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 711 "preview_url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/small/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 712 "remote_url": "http://fossbros-anonymous.io/attachments/original/13bbc3f8-2b5e-46ea-9531-40b4974d9912.jpg", 713 "preview_remote_url": "http://fossbros-anonymous.io/attachments/small/a499f55b-2d1e-4acd-98d2-1ac2ba6d79b9.jpg", 714 "meta": { 715 "original": { 716 "width": 472, 717 "height": 291, 718 "size": "472x291", 719 "aspect": 1.6219932 720 }, 721 "small": { 722 "width": 472, 723 "height": 291, 724 "size": "472x291", 725 "aspect": 1.6219932 726 }, 727 "focus": { 728 "x": 0, 729 "y": 0 730 } 731 }, 732 "description": "tweet from thoughts of dog: i drank. all the water. in my bowl. earlier. but just now. i returned. to the same bowl. and it was. full again.. the bowl. is haunted", 733 "blurhash": "LARysgM_IU_3~pD%M_Rj_39FIAt6" 734 } 735 ], 736 "mentions": [], 737 "tags": [], 738 "emojis": [], 739 "card": null, 740 "poll": null 741 } 742 ], 743 "rule_ids": [], 744 "action_taken_comment": null 745 } 746 ]`, string(b)) 747 748 suite.Equal(`<http://localhost:8080/api/v1/admin/reports?limit=20&max_id=01GP3AWY4CRDVRNZKW0TEAMB5R&account_id=01F8MH5NBDF2MV7CTC4Q5128HF>; rel="next", <http://localhost:8080/api/v1/admin/reports?limit=20&min_id=01GP3AWY4CRDVRNZKW0TEAMB5R&account_id=01F8MH5NBDF2MV7CTC4Q5128HF>; rel="prev"`, link) 749 } 750 751 func (suite *ReportsGetTestSuite) TestReportsGetTargetAccount() { 752 testAccount := suite.testAccounts["admin_account"] 753 testToken := suite.testTokens["admin_account"] 754 testUser := suite.testUsers["admin_account"] 755 targetAccount := suite.testAccounts["remote_account_1"] 756 757 reports, link, err := suite.getReports(testAccount, testToken, testUser, http.StatusOK, "", nil, "", targetAccount.ID, "", "", "", 20) 758 suite.NoError(err) 759 suite.NotEmpty(reports) 760 761 b, err := json.MarshalIndent(&reports, "", " ") 762 suite.NoError(err) 763 764 suite.Equal(`[ 765 { 766 "id": "01GP3AWY4CRDVRNZKW0TEAMB5R", 767 "action_taken": false, 768 "action_taken_at": null, 769 "category": "other", 770 "comment": "dark souls sucks, please yeet this nerd", 771 "forwarded": true, 772 "created_at": "2022-05-14T10:20:03.000Z", 773 "updated_at": "2022-05-14T10:20:03.000Z", 774 "account": { 775 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 776 "username": "1happyturtle", 777 "domain": null, 778 "created_at": "2022-06-04T13:12:00.000Z", 779 "email": "tortle.dude@example.org", 780 "ip": "118.44.18.196", 781 "ips": [], 782 "locale": "en", 783 "invite_request": null, 784 "role": { 785 "name": "user" 786 }, 787 "confirmed": true, 788 "approved": true, 789 "disabled": false, 790 "silenced": false, 791 "suspended": false, 792 "account": { 793 "id": "01F8MH5NBDF2MV7CTC4Q5128HF", 794 "username": "1happyturtle", 795 "acct": "1happyturtle", 796 "display_name": "happy little turtle :3", 797 "locked": true, 798 "discoverable": false, 799 "bot": false, 800 "created_at": "2022-06-04T13:12:00.000Z", 801 "note": "\u003cp\u003ei post about things that concern me\u003c/p\u003e", 802 "url": "http://localhost:8080/@1happyturtle", 803 "avatar": "", 804 "avatar_static": "", 805 "header": "http://localhost:8080/assets/default_header.png", 806 "header_static": "http://localhost:8080/assets/default_header.png", 807 "followers_count": 1, 808 "following_count": 1, 809 "statuses_count": 7, 810 "last_status_at": "2021-10-20T10:40:37.000Z", 811 "emojis": [], 812 "fields": [ 813 { 814 "name": "should you follow me?", 815 "value": "maybe!", 816 "verified_at": null 817 }, 818 { 819 "name": "age", 820 "value": "120", 821 "verified_at": null 822 } 823 ], 824 "role": { 825 "name": "user" 826 } 827 }, 828 "created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG" 829 }, 830 "target_account": { 831 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 832 "username": "foss_satan", 833 "domain": "fossbros-anonymous.io", 834 "created_at": "2021-09-26T10:52:36.000Z", 835 "email": "", 836 "ip": null, 837 "ips": [], 838 "locale": "", 839 "invite_request": null, 840 "role": { 841 "name": "user" 842 }, 843 "confirmed": false, 844 "approved": false, 845 "disabled": false, 846 "silenced": false, 847 "suspended": false, 848 "account": { 849 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 850 "username": "foss_satan", 851 "acct": "foss_satan@fossbros-anonymous.io", 852 "display_name": "big gerald", 853 "locked": false, 854 "discoverable": true, 855 "bot": false, 856 "created_at": "2021-09-26T10:52:36.000Z", 857 "note": "i post about like, i dunno, stuff, or whatever!!!!", 858 "url": "http://fossbros-anonymous.io/@foss_satan", 859 "avatar": "", 860 "avatar_static": "", 861 "header": "http://localhost:8080/assets/default_header.png", 862 "header_static": "http://localhost:8080/assets/default_header.png", 863 "followers_count": 0, 864 "following_count": 0, 865 "statuses_count": 1, 866 "last_status_at": "2021-09-20T10:40:37.000Z", 867 "emojis": [], 868 "fields": [] 869 } 870 }, 871 "assigned_account": null, 872 "action_taken_by_account": null, 873 "statuses": [ 874 { 875 "id": "01FVW7JHQFSFK166WWKR8CBA6M", 876 "created_at": "2021-09-20T10:40:37.000Z", 877 "in_reply_to_id": null, 878 "in_reply_to_account_id": null, 879 "sensitive": false, 880 "spoiler_text": "", 881 "visibility": "unlisted", 882 "language": "en", 883 "uri": "http://fossbros-anonymous.io/users/foss_satan/statuses/01FVW7JHQFSFK166WWKR8CBA6M", 884 "url": "http://fossbros-anonymous.io/@foss_satan/statuses/01FVW7JHQFSFK166WWKR8CBA6M", 885 "replies_count": 0, 886 "reblogs_count": 0, 887 "favourites_count": 0, 888 "favourited": false, 889 "reblogged": false, 890 "muted": false, 891 "bookmarked": false, 892 "pinned": false, 893 "content": "dark souls status bot: \"thoughts of dog\"", 894 "reblog": null, 895 "account": { 896 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 897 "username": "foss_satan", 898 "acct": "foss_satan@fossbros-anonymous.io", 899 "display_name": "big gerald", 900 "locked": false, 901 "discoverable": true, 902 "bot": false, 903 "created_at": "2021-09-26T10:52:36.000Z", 904 "note": "i post about like, i dunno, stuff, or whatever!!!!", 905 "url": "http://fossbros-anonymous.io/@foss_satan", 906 "avatar": "", 907 "avatar_static": "", 908 "header": "http://localhost:8080/assets/default_header.png", 909 "header_static": "http://localhost:8080/assets/default_header.png", 910 "followers_count": 0, 911 "following_count": 0, 912 "statuses_count": 1, 913 "last_status_at": "2021-09-20T10:40:37.000Z", 914 "emojis": [], 915 "fields": [] 916 }, 917 "media_attachments": [ 918 { 919 "id": "01FVW7RXPQ8YJHTEXYPE7Q8ZY0", 920 "type": "image", 921 "url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/original/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 922 "text_url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/original/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 923 "preview_url": "http://localhost:8080/fileserver/01F8MH5ZK5VRH73AKHQM6Y9VNX/attachment/small/01FVW7RXPQ8YJHTEXYPE7Q8ZY0.jpg", 924 "remote_url": "http://fossbros-anonymous.io/attachments/original/13bbc3f8-2b5e-46ea-9531-40b4974d9912.jpg", 925 "preview_remote_url": "http://fossbros-anonymous.io/attachments/small/a499f55b-2d1e-4acd-98d2-1ac2ba6d79b9.jpg", 926 "meta": { 927 "original": { 928 "width": 472, 929 "height": 291, 930 "size": "472x291", 931 "aspect": 1.6219932 932 }, 933 "small": { 934 "width": 472, 935 "height": 291, 936 "size": "472x291", 937 "aspect": 1.6219932 938 }, 939 "focus": { 940 "x": 0, 941 "y": 0 942 } 943 }, 944 "description": "tweet from thoughts of dog: i drank. all the water. in my bowl. earlier. but just now. i returned. to the same bowl. and it was. full again.. the bowl. is haunted", 945 "blurhash": "LARysgM_IU_3~pD%M_Rj_39FIAt6" 946 } 947 ], 948 "mentions": [], 949 "tags": [], 950 "emojis": [], 951 "card": null, 952 "poll": null 953 } 954 ], 955 "rule_ids": [], 956 "action_taken_comment": null 957 } 958 ]`, string(b)) 959 960 suite.Equal(`<http://localhost:8080/api/v1/admin/reports?limit=20&max_id=01GP3AWY4CRDVRNZKW0TEAMB5R&target_account_id=01F8MH5ZK5VRH73AKHQM6Y9VNX>; rel="next", <http://localhost:8080/api/v1/admin/reports?limit=20&min_id=01GP3AWY4CRDVRNZKW0TEAMB5R&target_account_id=01F8MH5ZK5VRH73AKHQM6Y9VNX>; rel="prev"`, link) 961 } 962 963 func (suite *ReportsGetTestSuite) TestReportsGetResolvedTargetAccount() { 964 testAccount := suite.testAccounts["admin_account"] 965 testToken := suite.testTokens["admin_account"] 966 testUser := suite.testUsers["admin_account"] 967 resolved := testrig.FalseBool() 968 targetAccount := suite.testAccounts["local_account_2"] 969 970 reports, link, err := suite.getReports(testAccount, testToken, testUser, http.StatusOK, "", resolved, "", targetAccount.ID, "", "", "", 20) 971 suite.NoError(err) 972 suite.Empty(reports) 973 974 b, err := json.MarshalIndent(&reports, "", " ") 975 suite.NoError(err) 976 977 suite.Equal(`[]`, string(b)) 978 suite.Empty(link) 979 } 980 981 func (suite *ReportsGetTestSuite) TestReportsGetNotAdmin() { 982 testAccount := suite.testAccounts["local_account_1"] 983 testToken := suite.testTokens["local_account_1"] 984 testUser := suite.testUsers["local_account_1"] 985 986 reports, _, err := suite.getReports(testAccount, testToken, testUser, http.StatusForbidden, `{"error":"Forbidden: user 01F8MGVGPHQ2D3P3X0454H54Z5 not an admin"}`, nil, "", "", "", "", "", 20) 987 suite.NoError(err) 988 suite.Empty(reports) 989 } 990 991 func (suite *ReportsGetTestSuite) TestReportsGetZeroLimit() { 992 testAccount := suite.testAccounts["admin_account"] 993 testToken := suite.testTokens["admin_account"] 994 testUser := suite.testUsers["admin_account"] 995 996 reports, link, err := suite.getReports(testAccount, testToken, testUser, http.StatusOK, "", nil, "", "", "", "", "", 0) 997 suite.NoError(err) 998 suite.Len(reports, 2) 999 1000 // Limit in Link header should be set to 100 1001 suite.Equal(`<http://localhost:8080/api/v1/admin/reports?limit=100&max_id=01GP3AWY4CRDVRNZKW0TEAMB5R>; rel="next", <http://localhost:8080/api/v1/admin/reports?limit=100&min_id=01GP3DFY9XQ1TJMZT5BGAZPXX7>; rel="prev"`, link) 1002 } 1003 1004 func (suite *ReportsGetTestSuite) TestReportsGetHighLimit() { 1005 testAccount := suite.testAccounts["admin_account"] 1006 testToken := suite.testTokens["admin_account"] 1007 testUser := suite.testUsers["admin_account"] 1008 1009 reports, link, err := suite.getReports(testAccount, testToken, testUser, http.StatusOK, "", nil, "", "", "", "", "", 2000) 1010 suite.NoError(err) 1011 suite.Len(reports, 2) 1012 1013 // Limit in Link header should be set to 100 1014 suite.Equal(`<http://localhost:8080/api/v1/admin/reports?limit=100&max_id=01GP3AWY4CRDVRNZKW0TEAMB5R>; rel="next", <http://localhost:8080/api/v1/admin/reports?limit=100&min_id=01GP3DFY9XQ1TJMZT5BGAZPXX7>; rel="prev"`, link) 1015 } 1016 1017 func TestReportsGetTestSuite(t *testing.T) { 1018 suite.Run(t, &ReportsGetTestSuite{}) 1019 }