You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.2 KiB

  1. package controller
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. "github.com/QuantumNous/new-api/common"
  7. "github.com/gin-gonic/gin"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func TestGetOptionsOmitsSensitiveSuffixes(t *testing.T) {
  11. common.OptionMapRWMutex.Lock()
  12. oldOptions := common.OptionMap
  13. common.OptionMap = map[string]string{
  14. "PublicOption": "visible", "AccessToken": "secret", "WebhookSecret": "secret",
  15. "ProviderKey": "secret", "lowercase_secret": "secret", "service_api_key": "secret",
  16. }
  17. common.OptionMapRWMutex.Unlock()
  18. t.Cleanup(func() {
  19. common.OptionMapRWMutex.Lock()
  20. common.OptionMap = oldOptions
  21. common.OptionMapRWMutex.Unlock()
  22. })
  23. router := gin.New()
  24. router.GET("/", GetOptions)
  25. response := httptest.NewRecorder()
  26. router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/", nil))
  27. require.Equal(t, http.StatusOK, response.Code)
  28. body := response.Body.String()
  29. require.Contains(t, body, "PublicOption")
  30. require.NotContains(t, body, "AccessToken")
  31. require.NotContains(t, body, "WebhookSecret")
  32. require.NotContains(t, body, "ProviderKey")
  33. require.NotContains(t, body, "lowercase_secret")
  34. require.NotContains(t, body, "service_api_key")
  35. }