4
0

icon_integration_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. "miniflux.app/v2/internal/http/server/servertest"
  9. )
  10. func TestGetFeedIcon(t *testing.T) {
  11. t.Parallel()
  12. fixture := servertest.NewFeedFixture(t)
  13. regularUserClient, _ := 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. client := newAdminClient(t)
  45. _, err := client.FeedIcon(123456789)
  46. if !errors.Is(err, miniflux.ErrNotFound) {
  47. t.Fatalf(`Fetching the icon of an inexisting feed should raise an error, got %v`, err)
  48. }
  49. }
  50. func TestGetIconWithInexistingIconID(t *testing.T) {
  51. t.Parallel()
  52. client := newAdminClient(t)
  53. _, err := client.Icon(123456789)
  54. if !errors.Is(err, miniflux.ErrNotFound) {
  55. t.Fatalf(`Fetching an inexisting icon should return a "not found" error, got %v`, err)
  56. }
  57. }
  58. func TestGetIconByIconIDFromAnotherUser(t *testing.T) {
  59. t.Parallel()
  60. fixture := servertest.NewFeedFixture(t)
  61. // The owner subscribes to a feed, which fetches and stores its icon.
  62. ownerClient, _ := newRegularUser(t)
  63. feedID := fixture.Subscribe(t, ownerClient)
  64. ownerIcon, err := ownerClient.FeedIcon(feedID)
  65. if err != nil {
  66. t.Fatal(err)
  67. }
  68. if ownerIcon == nil {
  69. t.Fatalf(`Invalid icon, got nil`)
  70. }
  71. // The owner can fetch its own icon by icon ID.
  72. if _, err := ownerClient.Icon(ownerIcon.ID); err != nil {
  73. t.Fatalf(`The owner should be able to fetch its own icon, got %v`, err)
  74. }
  75. // Another user without access to that feed must not be able to fetch the icon.
  76. otherClient, _ := newRegularUser(t)
  77. if _, err := otherClient.Icon(ownerIcon.ID); !errors.Is(err, miniflux.ErrNotFound) {
  78. t.Fatalf(`Fetching an icon owned by another user should return a "not found" error, got %v`, err)
  79. }
  80. }