4
0

response_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package googlereader // import "miniflux.app/v2/internal/googlereader"
  4. import (
  5. "net/http"
  6. "net/http/httptest"
  7. "testing"
  8. )
  9. func TestLoginResponseString(t *testing.T) {
  10. result := loginResponse{SID: "user/sid", LSID: "user/lsid", Auth: "user/auth"}.String()
  11. expected := "SID=user/sid\nLSID=user/lsid\nAuth=user/auth\n"
  12. if result != expected {
  13. t.Errorf(`Unexpected login response, got %q instead of %q`, result, expected)
  14. }
  15. }
  16. func TestSendUnauthorizedResponse(t *testing.T) {
  17. recorder := httptest.NewRecorder()
  18. sendUnauthorizedResponse(recorder, httptest.NewRequest(http.MethodGet, "/reader/api/0/user-info", nil))
  19. checkUnauthorizedResponse(t, recorder)
  20. }
  21. func checkUnauthorizedResponse(t *testing.T, recorder *httptest.ResponseRecorder) {
  22. t.Helper()
  23. if recorder.Code != http.StatusUnauthorized {
  24. t.Errorf(`Unexpected status code, got %d instead of %d`, recorder.Code, http.StatusUnauthorized)
  25. }
  26. if value := recorder.Header().Get("X-Reader-Google-Bad-Token"); value != "true" {
  27. t.Errorf(`Unexpected X-Reader-Google-Bad-Token header, got %q`, value)
  28. }
  29. if value := recorder.Header().Get("Content-Type"); value != "text/plain; charset=utf-8" {
  30. t.Errorf(`Unexpected Content-Type header, got %q`, value)
  31. }
  32. if body := recorder.Body.String(); body != "Unauthorized" {
  33. t.Errorf(`Unexpected body, got %q`, body)
  34. }
  35. }