Merge branch 'fixsse' into 'staging'

Fixsse

See merge request pena-services/customer!56
This commit is contained in:
Mikhail 2024-06-08 17:36:36 +00:00
commit c5fa3bdf5c
3 changed files with 15 additions and 11 deletions

@ -827,8 +827,11 @@ paths:
- account - account
summary: Получение изменений аккаунта через SSE summary: Получение изменений аккаунта через SSE
operationId: accountPipe operationId: accountPipe
security: parameters:
- Bearer: [ ] - name: Authorization
in: query
description: токен пользователя
required: true
responses: responses:
'200': '200':
description: Успешный ответ description: Успешный ответ

@ -48,12 +48,17 @@ func authenticate(jwtUtil *JWT, c *fiber.Ctx) error {
func parseJWSFromRequest(c *fiber.Ctx) (string, error) { func parseJWSFromRequest(c *fiber.Ctx) (string, error) {
header := c.Get("Authorization") header := c.Get("Authorization")
if header == "" || !strings.HasPrefix(header, prefix) { if header != "" && strings.HasPrefix(header, prefix) {
return strings.TrimPrefix(header, prefix), nil
}
token := c.Query("Authorization")
if token == "" {
return "", errors.New( return "", errors.New(
fmt.Errorf("failed to parse jws from request header: %s", header), fmt.Errorf("failed to parse jws from request: no valid token found"),
errors.ErrNoAccess, errors.ErrNoAccess,
) )
} }
return strings.TrimPrefix(header, prefix), nil return token, nil
} }

@ -11,14 +11,13 @@ import (
) )
func TestAccountPipe(t *testing.T) { func TestAccountPipe(t *testing.T) {
url := "http://localhost:8082/account/pipe"
jwtUtil := helpers.InitializeJWT() jwtUtil := helpers.InitializeJWT()
token, tokenErr := jwtUtil.Create("64e53ed187392e122e5d3d50") token, tokenErr := jwtUtil.Create("64ebda4387392e122e5d411f")
if !assert.NoError(t, tokenErr) { if !assert.NoError(t, tokenErr) {
return return
} }
url := fmt.Sprintf("http://localhost:8082/account/pipe?token=%s", token)
client := &http.Client{ client := &http.Client{
Timeout: 100 * time.Second, Timeout: 100 * time.Second,
} }
@ -28,11 +27,8 @@ func TestAccountPipe(t *testing.T) {
return return
} }
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Accept", "text/event-stream") req.Header.Set("Accept", "text/event-stream")
fmt.Println(token)
resp, err := client.Do(req) resp, err := client.Do(req)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
return return