WebClient: fix test cases
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
ff2eed8ee9
commit
f721cf5c40
3 changed files with 20 additions and 6 deletions
|
@ -16,6 +16,7 @@ package httpd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -23,18 +24,29 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/drakkan/sftpgo/v2/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFlashMessages(t *testing.T) {
|
func TestFlashMessages(t *testing.T) {
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
req, err := http.NewRequest(http.MethodGet, "/url", nil)
|
req, err := http.NewRequest(http.MethodGet, "/url", nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
message := "test message"
|
message := flashMessage{
|
||||||
setFlashMessage(rr, req, flashMessage{ErrorString: message})
|
ErrorString: "error",
|
||||||
req.Header.Set("Cookie", fmt.Sprintf("%v=%v", flashCookieName, base64.URLEncoding.EncodeToString([]byte(message))))
|
I18nMessage: util.I18nChangePwdTitle,
|
||||||
|
}
|
||||||
|
setFlashMessage(rr, req, message)
|
||||||
|
value, err := json.Marshal(message)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
req.Header.Set("Cookie", fmt.Sprintf("%v=%v", flashCookieName, base64.URLEncoding.EncodeToString(value)))
|
||||||
msg := getFlashMessage(rr, req)
|
msg := getFlashMessage(rr, req)
|
||||||
assert.Equal(t, message, msg.ErrorString)
|
assert.Equal(t, message, msg)
|
||||||
|
assert.Equal(t, util.I18nChangePwdTitle, msg.getI18nError().Message)
|
||||||
req.Header.Set("Cookie", fmt.Sprintf("%v=%v", flashCookieName, "a"))
|
req.Header.Set("Cookie", fmt.Sprintf("%v=%v", flashCookieName, "a"))
|
||||||
msg = getFlashMessage(rr, req)
|
msg = getFlashMessage(rr, req)
|
||||||
assert.Empty(t, msg)
|
assert.Empty(t, msg)
|
||||||
|
req.Header.Set("Cookie", fmt.Sprintf("%v=%v", flashCookieName, "YQ=="))
|
||||||
|
msg = getFlashMessage(rr, req)
|
||||||
|
assert.Empty(t, msg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9806,7 +9806,7 @@ func TestWebUserTwoFactorLogin(t *testing.T) {
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
rr = executeRequest(req)
|
rr = executeRequest(req)
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
assert.Contains(t, rr.Body.String(), "Two factory authentication is not enabled")
|
assert.Contains(t, rr.Body.String(), util.I18n2FADisabled)
|
||||||
|
|
||||||
req, err = http.NewRequest(http.MethodPost, webClientTwoFactorPath, bytes.NewBuffer([]byte(form.Encode())))
|
req, err = http.NewRequest(http.MethodPost, webClientTwoFactorPath, bytes.NewBuffer([]byte(form.Encode())))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -59,7 +59,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
|
||||||
<div data-i18n="general.or" class="text-center text-muted text-uppercase fw-bold mb-5">or</div>
|
<div data-i18n="general.or" class="text-center text-muted text-uppercase fw-bold mb-5">or</div>
|
||||||
{{- end}}
|
{{- end}}
|
||||||
<a href="{{.OpenIDLoginURL}}" class="btn btn-flex flex-center btn-light btn-lg w-100 mb-5">
|
<a href="{{.OpenIDLoginURL}}" class="btn btn-flex flex-center btn-light btn-lg w-100 mb-5">
|
||||||
<img data-i18n="login.signin_openid" alt="Logo" src="{{.StaticURL}}/img/openid-logo.png" class="h-20px me-3" />Sign in with OpenID</a>
|
<img alt="Logo" src="{{.StaticURL}}/img/openid-logo.png" class="h-20px me-3" />
|
||||||
|
<span data-i18n="login.signin_openid">Sign in with OpenID</span>
|
||||||
|
</a>
|
||||||
{{- end}}
|
{{- end}}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue