From b3e460eebd5334fa1a8a41966aa6aafde0a3e227 Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 3 Jun 2022 22:25:52 -0500 Subject: [PATCH] sleep in anon test to prevent limiter --- backend/app/cmd/server_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/app/cmd/server_test.go b/backend/app/cmd/server_test.go index 86387c9e..7f6c3518 100644 --- a/backend/app/cmd/server_test.go +++ b/backend/app/cmd/server_test.go @@ -143,36 +143,42 @@ func TestServerApp_AnonMode(t *testing.T) { assert.Equal(t, http.StatusCreated, resp.StatusCode) // try to login with non-latin name + time.Sleep(time.Second) resp, err = client.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=Раз_Два%20%20Три_34567&aud=remark", port)) require.NoError(t, err) defer resp.Body.Close() assert.Equal(t, http.StatusOK, resp.StatusCode) // try to login with bad name + time.Sleep(time.Second) resp, err = client.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=**blah123&aud=remark", port)) require.NoError(t, err) defer resp.Body.Close() assert.Equal(t, http.StatusForbidden, resp.StatusCode) // try to login with short name + time.Sleep(time.Second) resp, err = client.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=bl%%20%%20&aud=remark", port)) require.NoError(t, err) defer resp.Body.Close() assert.Equal(t, http.StatusForbidden, resp.StatusCode) // try to login with name what have space in prefix + time.Sleep(time.Second) resp, err = client.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=%%20somebody&aud=remark", port)) require.NoError(t, err) defer resp.Body.Close() assert.Equal(t, http.StatusForbidden, resp.StatusCode) // try to login with name what have space in suffix + time.Sleep(time.Second) resp, err = client.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=somebody%%20&aud=remark", port)) require.NoError(t, err) defer resp.Body.Close() assert.Equal(t, http.StatusForbidden, resp.StatusCode) // try to login with long name + time.Sleep(time.Second) ln := strings.Repeat("x", 65) resp, err = client.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=%s&aud=remark", port, ln)) require.NoError(t, err) @@ -180,12 +186,14 @@ func TestServerApp_AnonMode(t *testing.T) { assert.Equal(t, http.StatusForbidden, resp.StatusCode) // try to login with admin name + time.Sleep(time.Second) resp, err = client.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=umpUtun&aud=remark", port)) require.NoError(t, err) defer resp.Body.Close() assert.Equal(t, http.StatusOK, resp.StatusCode) // try to add a comment as anonymous with admin name + time.Sleep(time.Second) req, err = http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/api/v1/comment", port), strings.NewReader(`{"text": "test 123", "locator":{"url": "https://radio-t.com/blah1", "site": "remark"}}`)) require.NoError(t, err)