|
@@ -20,6 +20,9 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "image"
|
|
|
+ "image/color"
|
|
|
+ "image/png"
|
|
|
"io"
|
|
|
"io/fs"
|
|
|
"math"
|
|
@@ -13350,10 +13353,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
|
|
|
form := make(url.Values)
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err := getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusForbidden, rr)
|
|
|
// parse form error
|
|
@@ -13371,10 +13376,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
form.Add("sftp_host_key_algos", ssh.InsecureCertAlgoDSAv01)
|
|
|
form.Set("sftp_pub_key_algos", ssh.InsecureKeyAlgoDSA)
|
|
|
form.Set("form_action", "sftp_submit")
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nError500Message) // invalid algo
|
|
@@ -13383,10 +13390,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
form.Set("sftp_pub_key_algos", ssh.InsecureKeyAlgoDSA)
|
|
|
form.Set("sftp_kex_algos", "diffie-hellman-group18-sha512")
|
|
|
form.Add("sftp_kex_algos", ssh.KeyExchangeDH16SHA512)
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
@@ -13401,10 +13410,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
assert.Contains(t, configs.SFTPD.KexAlgorithms, ssh.KeyExchangeDH16SHA512)
|
|
|
// invalid form action
|
|
|
form.Set("form_action", "")
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusBadRequest, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nError400Message)
|
|
@@ -13416,10 +13427,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
form.Set("smtp_password", defaultPassword)
|
|
|
form.Set("smtp_domain", "localdomain")
|
|
|
form.Set("smtp_auth", "100")
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nError500Message) // invalid smtp_auth
|
|
@@ -13430,10 +13443,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
form.Set("smtp_debug", "checked")
|
|
|
form.Set("smtp_oauth2_provider", "1")
|
|
|
form.Set("smtp_oauth2_client_id", "123")
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
@@ -13460,10 +13475,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
form.Set("smtp_password", redactedSecret)
|
|
|
form.Set("smtp_auth", "")
|
|
|
configs.SMTP.AuthType = 0 // empty will be converted to 0
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
@@ -13479,10 +13496,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
updatedConfigs.SMTP.Password = kms.NewSecret(sdkkms.SecretStatusSecretBox, encryptedPayload, secretKey, "")
|
|
|
err = dataprovider.UpdateConfigs(&updatedConfigs, "", "", "")
|
|
|
assert.NoError(t, err)
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
@@ -13492,19 +13511,23 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
form.Add("acme_protocols", "2")
|
|
|
form.Add("acme_protocols", "3")
|
|
|
form.Set("acme_domain", "example.com")
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
// no email set, validation will fail
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nErrorInvalidEmail)
|
|
|
form.Set("acme_domain", "")
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
@@ -13535,10 +13558,12 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
form.Add("acme_protocols", "1000")
|
|
|
form.Set("acme_domain", domain)
|
|
|
form.Set("acme_email", "email@example.com")
|
|
|
- req, err = http.NewRequest(http.MethodPost, webConfigsPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
assert.NoError(t, err)
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
@@ -13562,6 +13587,201 @@ func TestWebConfigsMock(t *testing.T) {
|
|
|
assert.NoError(t, err)
|
|
|
}
|
|
|
|
|
|
+func TestBrandingConfigMock(t *testing.T) {
|
|
|
+ err := dataprovider.UpdateConfigs(nil, "", "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+
|
|
|
+ webClientLogoPath := "/static/branding/webclient/logo.png"
|
|
|
+ webClientFaviconPath := "/static/branding/webclient/favicon.png"
|
|
|
+ webAdminLogoPath := "/static/branding/webadmin/logo.png"
|
|
|
+ webAdminFaviconPath := "/static/branding/webadmin/favicon.png"
|
|
|
+ // no custom log or favicon was set
|
|
|
+ for _, p := range []string{webClientLogoPath, webClientFaviconPath, webAdminLogoPath, webAdminFaviconPath} {
|
|
|
+ req, err := http.NewRequest(http.MethodGet, p, nil)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ rr := executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusNotFound, rr)
|
|
|
+ }
|
|
|
+
|
|
|
+ webToken, err := getJWTWebTokenFromTestServer(defaultTokenAuthUser, defaultTokenAuthPass)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ csrfToken, err := getCSRFTokenFromInternalPageMock(webConfigsPath, webToken)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ form := make(url.Values)
|
|
|
+ form.Set(csrfFormToken, csrfToken)
|
|
|
+ form.Set("form_action", "branding_submit")
|
|
|
+ form.Set("branding_webadmin_name", "Custom WebAdmin")
|
|
|
+ form.Set("branding_webadmin_short_name", "WebAdmin")
|
|
|
+ form.Set("branding_webadmin_disclaimer_name", "Admin disclaimer")
|
|
|
+ form.Set("branding_webadmin_disclaimer_url", "invalid, not a URL")
|
|
|
+ form.Set("branding_webclient_name", "Custom WebClient")
|
|
|
+ form.Set("branding_webclient_short_name", "WebClient")
|
|
|
+ form.Set("branding_webclient_disclaimer_name", "Client disclaimer")
|
|
|
+ form.Set("branding_webclient_disclaimer_url", "https://example.com")
|
|
|
+ b, contentType, err := getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err := http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr := executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nErrorInvalidDisclaimerURL)
|
|
|
+
|
|
|
+ form.Set("branding_webadmin_disclaimer_url", "https://example.net")
|
|
|
+ tmpFile := filepath.Join(os.TempDir(), util.GenerateUniqueID()+".png")
|
|
|
+ err = createTestPNG(tmpFile, 512, 512, color.RGBA{100, 200, 200, 0xff})
|
|
|
+ assert.NoError(t, err)
|
|
|
+
|
|
|
+ b, contentType, err = getMultipartFormData(form, "branding_webadmin_logo", tmpFile)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
|
+ // check
|
|
|
+ configs, err := dataprovider.GetConfigs()
|
|
|
+ assert.NoError(t, err)
|
|
|
+ assert.Equal(t, "Custom WebAdmin", configs.Branding.WebAdmin.Name)
|
|
|
+ assert.Equal(t, "WebAdmin", configs.Branding.WebAdmin.ShortName)
|
|
|
+ assert.Equal(t, "Admin disclaimer", configs.Branding.WebAdmin.DisclaimerName)
|
|
|
+ assert.Equal(t, "https://example.net", configs.Branding.WebAdmin.DisclaimerURL)
|
|
|
+ assert.Equal(t, "Custom WebClient", configs.Branding.WebClient.Name)
|
|
|
+ assert.Equal(t, "WebClient", configs.Branding.WebClient.ShortName)
|
|
|
+ assert.Equal(t, "Client disclaimer", configs.Branding.WebClient.DisclaimerName)
|
|
|
+ assert.Equal(t, "https://example.com", configs.Branding.WebClient.DisclaimerURL)
|
|
|
+ assert.Greater(t, len(configs.Branding.WebAdmin.Logo), 0)
|
|
|
+ assert.Len(t, configs.Branding.WebAdmin.Favicon, 0)
|
|
|
+ assert.Len(t, configs.Branding.WebClient.Logo, 0)
|
|
|
+ assert.Len(t, configs.Branding.WebClient.Favicon, 0)
|
|
|
+
|
|
|
+ err = createTestPNG(tmpFile, 256, 256, color.RGBA{120, 220, 220, 0xff})
|
|
|
+ assert.NoError(t, err)
|
|
|
+ form.Set("branding_webadmin_logo_remove", "0") // 0 preserves WebAdmin logo
|
|
|
+ b, contentType, err = getMultipartFormData(form, "branding_webadmin_favicon", tmpFile)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
|
+ configs, err = dataprovider.GetConfigs()
|
|
|
+ assert.NoError(t, err)
|
|
|
+ assert.Equal(t, "Custom WebAdmin", configs.Branding.WebAdmin.Name)
|
|
|
+ assert.Equal(t, "WebAdmin", configs.Branding.WebAdmin.ShortName)
|
|
|
+ assert.Equal(t, "Admin disclaimer", configs.Branding.WebAdmin.DisclaimerName)
|
|
|
+ assert.Equal(t, "https://example.net", configs.Branding.WebAdmin.DisclaimerURL)
|
|
|
+ assert.Equal(t, "Custom WebClient", configs.Branding.WebClient.Name)
|
|
|
+ assert.Equal(t, "WebClient", configs.Branding.WebClient.ShortName)
|
|
|
+ assert.Equal(t, "Client disclaimer", configs.Branding.WebClient.DisclaimerName)
|
|
|
+ assert.Equal(t, "https://example.com", configs.Branding.WebClient.DisclaimerURL)
|
|
|
+ assert.Greater(t, len(configs.Branding.WebAdmin.Logo), 0)
|
|
|
+ assert.Greater(t, len(configs.Branding.WebAdmin.Favicon), 0)
|
|
|
+ assert.Len(t, configs.Branding.WebClient.Logo, 0)
|
|
|
+ assert.Len(t, configs.Branding.WebClient.Favicon, 0)
|
|
|
+
|
|
|
+ err = createTestPNG(tmpFile, 256, 256, color.RGBA{80, 90, 110, 0xff})
|
|
|
+ assert.NoError(t, err)
|
|
|
+ b, contentType, err = getMultipartFormData(form, "branding_webclient_logo", tmpFile)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
|
+ configs, err = dataprovider.GetConfigs()
|
|
|
+ assert.NoError(t, err)
|
|
|
+ assert.Greater(t, len(configs.Branding.WebClient.Logo), 0)
|
|
|
+
|
|
|
+ err = createTestPNG(tmpFile, 256, 256, color.RGBA{120, 50, 120, 0xff})
|
|
|
+ assert.NoError(t, err)
|
|
|
+ b, contentType, err = getMultipartFormData(form, "branding_webclient_favicon", tmpFile)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
|
+ configs, err = dataprovider.GetConfigs()
|
|
|
+ assert.NoError(t, err)
|
|
|
+ assert.Greater(t, len(configs.Branding.WebClient.Favicon), 0)
|
|
|
+
|
|
|
+ for _, p := range []string{webClientLogoPath, webClientFaviconPath, webAdminLogoPath, webAdminFaviconPath} {
|
|
|
+ req, err := http.NewRequest(http.MethodGet, p, nil)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ rr := executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ }
|
|
|
+ // remove images
|
|
|
+ form.Set("branding_webadmin_logo_remove", "1")
|
|
|
+ form.Set("branding_webclient_logo_remove", "1")
|
|
|
+ form.Set("branding_webadmin_favicon_remove", "1")
|
|
|
+ form.Set("branding_webclient_favicon_remove", "1")
|
|
|
+ b, contentType, err = getMultipartFormData(form, "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nConfigsOK)
|
|
|
+ configs, err = dataprovider.GetConfigs()
|
|
|
+ assert.NoError(t, err)
|
|
|
+ assert.Len(t, configs.Branding.WebAdmin.Logo, 0)
|
|
|
+ assert.Len(t, configs.Branding.WebAdmin.Favicon, 0)
|
|
|
+ assert.Len(t, configs.Branding.WebClient.Logo, 0)
|
|
|
+ assert.Len(t, configs.Branding.WebClient.Favicon, 0)
|
|
|
+ for _, p := range []string{webClientLogoPath, webClientFaviconPath, webAdminLogoPath, webAdminFaviconPath} {
|
|
|
+ req, err := http.NewRequest(http.MethodGet, p, nil)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ rr := executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusNotFound, rr)
|
|
|
+ }
|
|
|
+ form.Del("branding_webadmin_logo_remove")
|
|
|
+ form.Del("branding_webclient_logo_remove")
|
|
|
+ form.Del("branding_webadmin_favicon_remove")
|
|
|
+ form.Del("branding_webclient_favicon_remove")
|
|
|
+ // image too large
|
|
|
+ err = createTestPNG(tmpFile, 768, 512, color.RGBA{120, 50, 120, 0xff})
|
|
|
+ assert.NoError(t, err)
|
|
|
+ b, contentType, err = getMultipartFormData(form, "branding_webclient_logo", tmpFile)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nErrorInvalidPNGSize)
|
|
|
+ // not a png image
|
|
|
+ err = createTestFile(tmpFile, 128)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ b, contentType, err = getMultipartFormData(form, "branding_webclient_logo", tmpFile)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webConfigsPath, &b)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nErrorInvalidPNG)
|
|
|
+
|
|
|
+ err = os.Remove(tmpFile)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ err = dataprovider.UpdateConfigs(nil, "", "", "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+}
|
|
|
+
|
|
|
func TestSFTPLoopError(t *testing.T) {
|
|
|
user1 := getTestUser()
|
|
|
user2 := getTestUser()
|
|
@@ -26798,6 +27018,23 @@ func isDbDefenderSupported() bool {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func createTestPNG(name string, width, height int, imgColor color.Color) error {
|
|
|
+ upLeft := image.Point{0, 0}
|
|
|
+ lowRight := image.Point{width, height}
|
|
|
+ img := image.NewRGBA(image.Rectangle{upLeft, lowRight})
|
|
|
+ for x := 0; x < width; x++ {
|
|
|
+ for y := 0; y < height; y++ {
|
|
|
+ img.Set(x, y, imgColor)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f, err := os.Create(name)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ defer f.Close()
|
|
|
+ return png.Encode(f, img)
|
|
|
+}
|
|
|
+
|
|
|
func BenchmarkSecretDecryption(b *testing.B) {
|
|
|
s := kms.NewPlainSecret("test data")
|
|
|
s.SetAdditionalData("username")
|