ci / api / api (push) Successful in 55s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m6s
ci / db / db (push) Successful in 52s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m38s
release / android (APK в релиз) (push) Successful in 3m50s
ci / ts / ts (packages + web) (push) Successful in 3m20s
release / release (версия и заметки) (push) Successful in 5s
release / desktop (Linux и Windows в релиз) (push) Successful in 44m45s
release / prune (старые файлы и прогоны) (push) Successful in 7s
61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
package library
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"pipu/api/internal/api/gen"
|
|
"pipu/api/internal/auth"
|
|
)
|
|
|
|
type analysisErrorStore struct {
|
|
SourceStore
|
|
rows []AnalysisError
|
|
after uuid.UUID
|
|
limit int
|
|
}
|
|
|
|
func (s *analysisErrorStore) AnalysisErrors(_ context.Context, after uuid.UUID, limit int) ([]AnalysisError, error) {
|
|
s.after, s.limit = after, limit
|
|
return s.rows, nil
|
|
}
|
|
|
|
func TestAnalysisErrorsPermissionsAndPagination(t *testing.T) {
|
|
first, second := uuid.New(), uuid.New()
|
|
store := &analysisErrorStore{rows: []AnalysisError{{TrackID: first, Title: "One"}, {TrackID: second, Title: "Two"}}}
|
|
h := &Handler{svc: &Service{SourceService: &SourceService{store: store}}}
|
|
limit := 1
|
|
req := gen.ListAnalysisErrorsRequestObject{Params: gen.ListAnalysisErrorsParams{Limit: &limit}}
|
|
for _, role := range []auth.Role{auth.RoleUser, auth.RoleModerator} {
|
|
_, err := h.ListAnalysisErrors(auth.WithPrincipal(context.Background(), auth.Principal{Role: role}), req)
|
|
require.Error(t, err)
|
|
require.Zero(t, store.limit, "unauthorized requests must not reach the store")
|
|
}
|
|
_, err := h.ListAnalysisErrors(context.Background(), req)
|
|
require.Error(t, err)
|
|
ctx := auth.WithPrincipal(context.Background(), auth.Principal{Role: auth.RoleAdmin})
|
|
resp, err := h.ListAnalysisErrors(ctx, req)
|
|
require.NoError(t, err)
|
|
page := resp.(gen.ListAnalysisErrors200JSONResponse)
|
|
require.Len(t, page.Items, 1)
|
|
require.Equal(t, first, page.Items[0].TrackId)
|
|
require.Nil(t, page.Items[0].RelPath, "a missing file must not hide the failed job")
|
|
require.Equal(t, 2, store.limit)
|
|
require.NotNil(t, page.NextCursor)
|
|
store.rows = store.rows[1:]
|
|
req.Params.Cursor = page.NextCursor
|
|
resp, err = h.ListAnalysisErrors(ctx, req)
|
|
require.NoError(t, err)
|
|
require.Equal(t, first, store.after)
|
|
require.Nil(t, resp.(gen.ListAnalysisErrors200JSONResponse).NextCursor)
|
|
for _, cursor := range []string{"!invalid", base64.RawURLEncoding.EncodeToString([]byte("not-a-uuid"))} {
|
|
req.Params.Cursor = &cursor
|
|
_, err = h.ListAnalysisErrors(ctx, req)
|
|
require.Error(t, err)
|
|
}
|
|
}
|