|
|
|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
@@ -157,12 +158,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {"invalid-csrf-token"},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", "invalid-csrf-token")
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
@@ -187,20 +188,20 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
csrfToken := findCsrfToken(html)
|
|
|
|
csrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
session := findCookie(resp, "id")
|
|
|
|
session := findCookie(resp, "id")
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"invalid@mail.de"},
|
|
|
|
"email": {"invalid@mail.de"},
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+session.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+session.Value)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
@@ -227,14 +228,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
csrfToken := findCsrfToken(html)
|
|
|
|
csrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
session := findCookie(resp, "id")
|
|
|
|
session := findCookie(resp, "id")
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"invalid-password"},
|
|
|
|
"password": {"invalid-password"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -242,6 +242,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+session.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+session.Value)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)
|
|
|
|
@@ -267,7 +268,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
anonymousCsrfToken := findCsrfToken(html)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -275,12 +276,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
|
|
|
|
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
@@ -314,7 +315,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(body)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, body)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -322,13 +323,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
|
|
|
|
timeStart := time.Now()
|
|
|
|
timeStart := time.Now()
|
|
|
|
@@ -348,7 +349,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
body, err = html.Parse(resp.Body)
|
|
|
|
body, err = html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken = findCsrfToken(body)
|
|
|
|
anonymousCsrfToken = findCsrfToken(t, body)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession = findCookie(resp, "id")
|
|
|
|
anonymousSession = findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -356,7 +357,6 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData = url.Values{
|
|
|
|
formData = url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"wrong-password"},
|
|
|
|
"password": {"wrong-password"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -364,6 +364,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
timeStart = time.Now()
|
|
|
|
timeStart = time.Now()
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
@@ -382,7 +383,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
body, err = html.Parse(resp.Body)
|
|
|
|
body, err = html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken = findCsrfToken(body)
|
|
|
|
anonymousCsrfToken = findCsrfToken(t, body)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession = findCookie(resp, "id")
|
|
|
|
anonymousSession = findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -390,7 +391,6 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
"email": {"invalid-mail@mail.de"},
|
|
|
|
"email": {"invalid-mail@mail.de"},
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -398,6 +398,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
timeStart = time.Now()
|
|
|
|
timeStart = time.Now()
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
@@ -427,7 +428,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(html)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -435,7 +436,6 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -443,6 +443,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
@@ -493,12 +494,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {"invalid-csrf-token"},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signin", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", "invalid-csrf-token")
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -516,7 +517,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(body)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, body)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -524,13 +525,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"insecure-password"},
|
|
|
|
"password": {"insecure-password"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signup", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signup", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -553,7 +554,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(body)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, body)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -561,13 +562,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"secure-Password!1"},
|
|
|
|
"password": {"secure-Password!1"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signup", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signup", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
timeStart := time.Now()
|
|
|
|
timeStart := time.Now()
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
timeEnd := time.Now()
|
|
|
|
timeEnd := time.Now()
|
|
|
|
@@ -590,7 +591,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(body)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, body)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
anonymousSession := findCookie(resp, "id")
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
assert.NotNil(t, anonymousSession)
|
|
|
|
@@ -598,13 +599,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"password": {"secure-Password!1"},
|
|
|
|
"password": {"secure-Password!1"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signup", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/signup", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSession.Value)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
timeStart := time.Now()
|
|
|
|
timeStart := time.Now()
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
timeEnd := time.Now()
|
|
|
|
timeEnd := time.Now()
|
|
|
|
@@ -826,12 +827,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
csrfToken := findCsrfToken(html)
|
|
|
|
csrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"password": {"wrong-password"},
|
|
|
|
"password": {"wrong-password"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/delete-account", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/delete-account", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -839,6 +839,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -864,7 +865,6 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {"wrong-csrf-token"},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/delete-account", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/delete-account", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -872,6 +872,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", "wrong-csrf-token")
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -886,12 +887,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"name": {"Name"},
|
|
|
|
"name": {"Name"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
@@ -899,13 +900,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData = url.Values{
|
|
|
|
formData = url.Values{
|
|
|
|
"name": {"Name"},
|
|
|
|
"name": {"Name"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/treasurechest/new", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/treasurechest/new", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
@@ -913,26 +914,26 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData = url.Values{
|
|
|
|
formData = url.Values{
|
|
|
|
"timestamp": {"2006-01-02"},
|
|
|
|
"timestamp": {"2006-01-02"},
|
|
|
|
"value": {"100.00"},
|
|
|
|
"value": {"100.00"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/transaction/new", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/transaction/new", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
|
|
formData = url.Values{
|
|
|
|
formData = url.Values{
|
|
|
|
"password": {"password"},
|
|
|
|
"password": {"password"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/delete-account", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/delete-account", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -985,7 +986,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(html)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
assert.NotEqual(t, "", anonymousSessionId)
|
|
|
|
assert.NotEqual(t, "", anonymousSessionId)
|
|
|
|
@@ -993,13 +994,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"current-password": {"password"},
|
|
|
|
"current-password": {"password"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1026,7 +1027,6 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"current-password": {"password"},
|
|
|
|
"current-password": {"password"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"csrf-token": {"invalid-csrf-token"},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -1034,6 +1034,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", "invalid-csrf-token")
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1069,19 +1070,19 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
csrfToken := findCsrfToken(html)
|
|
|
|
csrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"current-password": {"wrong-password"},
|
|
|
|
"current-password": {"wrong-password"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1117,19 +1118,19 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
csrfToken := findCsrfToken(html)
|
|
|
|
csrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"current-password": {"password"},
|
|
|
|
"current-password": {"password"},
|
|
|
|
"new-password": {"insecure-password"},
|
|
|
|
"new-password": {"insecure-password"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1176,13 +1177,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
csrfToken := findCsrfToken(html)
|
|
|
|
csrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"current-password": {"password"},
|
|
|
|
"current-password": {"password"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/change-password", strings.NewReader(formData.Encode()))
|
|
|
|
@@ -1190,6 +1190,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1267,12 +1268,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"csrf-token": {"invalid-csrf-token"},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", "invalid-csrf-token")
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1297,17 +1298,17 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.NotEqual(t, "", anonymousSessionId)
|
|
|
|
assert.NotEqual(t, "", anonymousSessionId)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(body)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, body)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"non-existent@mail.de"},
|
|
|
|
"email": {"non-existent@mail.de"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1337,17 +1338,17 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
assert.NotEqual(t, "", anonymousSessionId)
|
|
|
|
assert.NotEqual(t, "", anonymousSessionId)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
body, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(body)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, body)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1383,12 +1384,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(html)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
@@ -1396,6 +1396,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token=invalidToken")
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token=invalidToken")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
@@ -1424,7 +1425,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(html)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
token := "password-reset-token"
|
|
|
|
token := "password-reset-token"
|
|
|
|
@@ -1435,7 +1436,6 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
@@ -1443,6 +1443,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token="+url.QueryEscape(token))
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token="+url.QueryEscape(token))
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
@@ -1471,7 +1472,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
anonymousSessionId := findCookie(resp, "id").Value
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
anonymousCsrfToken := findCsrfToken(html)
|
|
|
|
anonymousCsrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
assert.NotEqual(t, "", anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
token := "password-reset-token"
|
|
|
|
token := "password-reset-token"
|
|
|
|
@@ -1482,7 +1483,6 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"new-password": {"insecure-password"},
|
|
|
|
"new-password": {"insecure-password"},
|
|
|
|
"csrf-token": {anonymousCsrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
@@ -1490,6 +1490,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+anonymousSessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token="+url.QueryEscape(token))
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token="+url.QueryEscape(token))
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", anonymousCsrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
@@ -1524,18 +1525,18 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
sessionId := findCookie(resp, "id").Value
|
|
|
|
sessionId := findCookie(resp, "id").Value
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
csrfToken := findCsrfToken(html)
|
|
|
|
csrfToken := findCsrfToken(t, html)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
assert.NotEqual(t, "", csrfToken)
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"email": {"mail@mail.de"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
@@ -1546,13 +1547,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData = url.Values{
|
|
|
|
formData = url.Values{
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"new-password": {"MyNewSecurePassword1!"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/api/auth/forgot-password-actual", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
req.Header.Set("HX-Request", "true")
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token="+url.QueryEscape(token))
|
|
|
|
req.Header.Set("HX-Current-URL", basePath+"/auth/change-password?token="+url.QueryEscape(token))
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
@@ -1668,12 +1669,12 @@ func TestIntegrationAccount(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"name": {"name"},
|
|
|
|
"name": {"name"},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/account/some-id", strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/account/some-id", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusSeeOther, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusSeeOther, resp.StatusCode)
|
|
|
|
@@ -1699,12 +1700,12 @@ func TestIntegrationAccount(t *testing.T) {
|
|
|
|
expectedName := "My great Account"
|
|
|
|
expectedName := "My great Account"
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"name": {expectedName},
|
|
|
|
"name": {expectedName},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
@@ -1718,12 +1719,12 @@ func TestIntegrationAccount(t *testing.T) {
|
|
|
|
expectedNewName := "My new Account"
|
|
|
|
expectedNewName := "My new Account"
|
|
|
|
formData = url.Values{
|
|
|
|
formData = url.Values{
|
|
|
|
"name": {expectedNewName},
|
|
|
|
"name": {expectedNewName},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/account/"+id.String(), strings.NewReader(formData.Encode()))
|
|
|
|
req, err = http.NewRequestWithContext(ctx, "POST", basePath+"/account/"+id.String(), strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
resp, err = httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
@@ -1769,12 +1770,12 @@ func TestIntegrationAccount(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"name": {expectedName1},
|
|
|
|
"name": {expectedName1},
|
|
|
|
"csrf-token": {csrfToken1},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId1)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId1)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken1)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
@@ -1810,13 +1811,13 @@ func TestIntegrationAccount(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
formData := url.Values{
|
|
|
|
formData := url.Values{
|
|
|
|
"name": {name},
|
|
|
|
"name": {name},
|
|
|
|
"csrf-token": {csrfToken},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", basePath+"/account/new", strings.NewReader(formData.Encode()))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
req.Header.Set("Cookie", "id="+sessionId)
|
|
|
|
|
|
|
|
req.Header.Set("csrf-token", csrfToken)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, status, resp.StatusCode, "for name: "+name)
|
|
|
|
assert.Equal(t, status, resp.StatusCode, "for name: "+name)
|
|
|
|
@@ -1859,7 +1860,7 @@ func createAnonymousSession(t *testing.T, ctx context.Context, basePath string)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
html, err := html.Parse(resp.Body)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
return findCsrfToken(html), findCookie(resp, "id").Value
|
|
|
|
return findCsrfToken(t, html), findCookie(resp, "id").Value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func findCookie(resp *http.Response, name string) *http.Cookie {
|
|
|
|
func findCookie(resp *http.Response, name string) *http.Cookie {
|
|
|
|
@@ -1958,19 +1959,19 @@ func waitForReady(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func findCsrfToken(data *html.Node) string {
|
|
|
|
func findCsrfToken(t *testing.T, data *html.Node) string {
|
|
|
|
attr := getTokenAttribute(data)
|
|
|
|
token := getTokenAttribute(t, data)
|
|
|
|
if attr != nil {
|
|
|
|
if token != "" {
|
|
|
|
return attr.Val
|
|
|
|
return token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if data.FirstChild != nil {
|
|
|
|
if data.FirstChild != nil {
|
|
|
|
if token := findCsrfToken(data.FirstChild); token != "" {
|
|
|
|
if token = findCsrfToken(t, data.FirstChild); token != "" {
|
|
|
|
return token
|
|
|
|
return token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if data.NextSibling != nil {
|
|
|
|
if data.NextSibling != nil {
|
|
|
|
if token := findCsrfToken(data.NextSibling); token != "" {
|
|
|
|
if token = findCsrfToken(t, data.NextSibling); token != "" {
|
|
|
|
return token
|
|
|
|
return token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1978,25 +1979,16 @@ func findCsrfToken(data *html.Node) string {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getTokenAttribute(data *html.Node) *html.Attribute {
|
|
|
|
func getTokenAttribute(t *testing.T, data *html.Node) string {
|
|
|
|
returnValue := false
|
|
|
|
|
|
|
|
for _, attr := range data.Attr {
|
|
|
|
for _, attr := range data.Attr {
|
|
|
|
if attr.Key == "name" && attr.Val == "csrf-token" {
|
|
|
|
if attr.Key == "hx-headers" {
|
|
|
|
returnValue = true
|
|
|
|
var data map[string]interface{}
|
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(attr.Val), &data)
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
return data["csrf-token"].(string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
if !returnValue {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, attr := range data.Attr {
|
|
|
|
|
|
|
|
if attr.Key == "value" {
|
|
|
|
|
|
|
|
return &attr
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func readBody(t *testing.T, body io.ReadCloser) string {
|
|
|
|
func readBody(t *testing.T, body io.ReadCloser) string {
|
|
|
|
|