icon_integration_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package api_test
  4. import (
  5. "errors"
  6. "testing"
  7. miniflux "miniflux.app/v2/client"
  8. )
  9. func TestGetFeedIcon(t *testing.T) {
  10. t.Parallel()
  11. testConfig := requireIntegrationTestConfig(t)
  12. fixture := newFeedFixture(t)
  13. regularUserClient, _ := testConfig.newRegularUser(t)
  14. feedID := fixture.subscribe(t, regularUserClient)
  15. icon, err := regularUserClient.FeedIcon(feedID)
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. if icon == nil {
  20. t.Fatalf(`Invalid icon, got nil`)
  21. }
  22. if icon.MimeType != "image/png" {
  23. t.Fatalf(`Invalid mime type, got %q`, icon.MimeType)
  24. }
  25. if len(icon.Data) == 0 {
  26. t.Fatalf(`Invalid data, got empty`)
  27. }
  28. icon, err = regularUserClient.Icon(icon.ID)
  29. if err != nil {
  30. t.Fatal(err)
  31. }
  32. if icon == nil {
  33. t.Fatalf(`Invalid icon, got nil`)
  34. }
  35. if icon.MimeType != "image/png" {
  36. t.Fatalf(`Invalid mime type, got %q`, icon.MimeType)
  37. }
  38. if len(icon.Data) == 0 {
  39. t.Fatalf(`Invalid data, got empty`)
  40. }
  41. }
  42. func TestGetFeedIconWithInexistingFeedID(t *testing.T) {
  43. t.Parallel()
  44. testConfig := requireIntegrationTestConfig(t)
  45. client := testConfig.newAdminClient()
  46. _, err := client.FeedIcon(123456789)
  47. if !errors.Is(err, miniflux.ErrNotFound) {
  48. t.Fatalf(`Fetching the icon of an inexisting feed should raise an error, got %v`, err)
  49. }
  50. }
  51. func TestGetIconWithInexistingIconID(t *testing.T) {
  52. t.Parallel()
  53. testConfig := requireIntegrationTestConfig(t)
  54. client := testConfig.newAdminClient()
  55. _, err := client.Icon(123456789)
  56. if !errors.Is(err, miniflux.ErrNotFound) {
  57. t.Fatalf(`Fetching an inexisting icon should return a "not found" error, got %v`, err)
  58. }
  59. }
  60. func TestGetIconByIconIDFromAnotherUser(t *testing.T) {
  61. t.Parallel()
  62. testConfig := requireIntegrationTestConfig(t)
  63. fixture := newFeedFixture(t)
  64. // The owner subscribes to a feed, which fetches and stores its icon.
  65. ownerClient, _ := testConfig.newRegularUser(t)
  66. feedID := fixture.subscribe(t, ownerClient)
  67. ownerIcon, err := ownerClient.FeedIcon(feedID)
  68. if err != nil {
  69. t.Fatal(err)
  70. }
  71. if ownerIcon == nil {
  72. t.Fatalf(`Invalid icon, got nil`)
  73. }
  74. // The owner can fetch its own icon by icon ID.
  75. if _, err := ownerClient.Icon(ownerIcon.ID); err != nil {
  76. t.Fatalf(`The owner should be able to fetch its own icon, got %v`, err)
  77. }
  78. // Another user without access to that feed must not be able to fetch the icon.
  79. otherClient, _ := testConfig.newRegularUser(t)
  80. if _, err := otherClient.Icon(ownerIcon.ID); !errors.Is(err, miniflux.ErrNotFound) {
  81. t.Fatalf(`Fetching an icon owned by another user should return a "not found" error, got %v`, err)
  82. }
  83. }