integration_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package form // import "miniflux.app/v2/internal/ui/form"
  4. import (
  5. "testing"
  6. )
  7. func TestValidateGoogleReader(t *testing.T) {
  8. scenarios := []struct {
  9. name string
  10. form IntegrationForm
  11. storedPasswordHash string
  12. expectError bool
  13. }{
  14. {
  15. name: "disabled without credentials",
  16. form: IntegrationForm{},
  17. },
  18. {
  19. name: "enabled with username and new password",
  20. form: IntegrationForm{GoogleReaderEnabled: true, GoogleReaderUsername: "user", GoogleReaderPassword: "secret"},
  21. },
  22. {
  23. name: "enabled with username and stored password",
  24. form: IntegrationForm{GoogleReaderEnabled: true, GoogleReaderUsername: "user"},
  25. storedPasswordHash: "$2a$10$hash",
  26. },
  27. {
  28. name: "enabled without password",
  29. form: IntegrationForm{GoogleReaderEnabled: true, GoogleReaderUsername: "user"},
  30. expectError: true,
  31. },
  32. {
  33. name: "enabled without username",
  34. form: IntegrationForm{GoogleReaderEnabled: true, GoogleReaderPassword: "secret"},
  35. storedPasswordHash: "$2a$10$hash",
  36. expectError: true,
  37. },
  38. {
  39. name: "enabled without username and password",
  40. form: IntegrationForm{GoogleReaderEnabled: true},
  41. expectError: true,
  42. },
  43. }
  44. for _, scenario := range scenarios {
  45. t.Run(scenario.name, func(t *testing.T) {
  46. validationErr := scenario.form.ValidateGoogleReader(scenario.storedPasswordHash)
  47. if scenario.expectError && validationErr == nil {
  48. t.Fatal("expected a validation error")
  49. }
  50. if !scenario.expectError && validationErr != nil {
  51. t.Fatalf("unexpected validation error: %v", validationErr)
  52. }
  53. })
  54. }
  55. }