Merge branch 'MSP-5262' into 'master'
Resolve MSP-5262 Closes MSP-5262 See merge request isp/isp-system-service!8
This commit is contained in:
commit
4b0510d276
20 files changed
+474
-38
No files matched your search
@@ -0,0 +1,58 @@
|
||||
name: Create and publish a Docker image
|
||||
|
||||
on:
|
||||
push
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
APP_NAME: ${{ github.event.repository.name }}
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Read version from file
|
||||
id: version_reader
|
||||
run: |
|
||||
VERSION=$(cat .version)
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: docker-container
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and push Docker image
|
||||
id: push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_reader.outputs.version }}
|
||||
${{ github.ref == 'refs/heads/main' && format('{0}/{1}:latest', env.REGISTRY, env.IMAGE_NAME) || ''}}
|
||||
labels: |
|
||||
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
|
||||
org.opencontainers.image.version=${{ steps.version_reader.outputs.version }}
|
||||
build-args: |
|
||||
app_name=${{ env.APP_NAME }}
|
||||
version=${{ steps.version_reader.outputs.version }}
|
||||
- name: Generate artifact attestation
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
|
||||
subject-digest: ${{ steps.push.outputs.digest }}
|
||||
push-to-registry: true
|
||||
@@ -1,3 +1,8 @@
|
||||
### v5.4.0
|
||||
* Добавлен новый endpoint: `/access_list/delete_list` для удаления методов из списка доступов у приложений
|
||||
### v5.3.1
|
||||
* добавлен `Dockerfile` и скрипт для сборки и публикации образа в `GitHub Contaier Registry`
|
||||
* обновлены зависимости
|
||||
### v5.3.0
|
||||
* Добавлен новый endpoint: `/application/get_application_by_token`
|
||||
### v5.2.1
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
FROM golang:1.24-alpine3.20 AS builder
|
||||
WORKDIR /build
|
||||
ARG version
|
||||
ENV version_env=$version
|
||||
ARG app_name
|
||||
ENV app_name_env=$app_name
|
||||
COPY . .
|
||||
RUN go build -ldflags="-X 'main.version=$version_env'" -o /main .
|
||||
|
||||
FROM alpine:3.20 AS runner
|
||||
|
||||
RUN apk add --no-cache tzdata && \
|
||||
cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime && \
|
||||
echo "Europe/Moscow" > /etc/timezone
|
||||
|
||||
ARG UID=10001
|
||||
ARG GID=10001
|
||||
|
||||
RUN addgroup -g ${GID} appuser
|
||||
RUN adduser \
|
||||
-D \
|
||||
-h "/nonexistent" \
|
||||
-s "/sbin/nologin" \
|
||||
-u "${UID}" \
|
||||
-G appuser \
|
||||
appuser
|
||||
|
||||
RUN mkdir -p /app/data
|
||||
RUN chown appuser:appuser /app/data
|
||||
VOLUME /app/data
|
||||
|
||||
USER appuser
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ARG app_name
|
||||
ENV app_name_env=$app_name
|
||||
COPY --from=builder main /app/$app_name_env
|
||||
COPY /conf/config.yml /app/config.yml
|
||||
COPY /conf/default_remote_config.json* /app/default_remote_config.json
|
||||
COPY /migrations /app/migrations
|
||||
|
||||
ENTRYPOINT /app/$app_name_env
|
||||
@@ -2,8 +2,11 @@ package assembly
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/txix-open/isp-kit/rc"
|
||||
|
||||
"isp-system-service/conf"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/app"
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
@@ -12,7 +15,6 @@ import (
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-system-service/conf"
|
||||
)
|
||||
|
||||
type Assembly struct {
|
||||
|
||||
@@ -15,6 +15,7 @@ type AccessListService interface {
|
||||
GetById(ctx context.Context, appId int) ([]domain.MethodInfo, error)
|
||||
SetOne(ctx context.Context, request domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error)
|
||||
SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error)
|
||||
DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error
|
||||
}
|
||||
|
||||
type AccessList struct {
|
||||
@@ -113,3 +114,30 @@ func (c AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteList godoc
|
||||
//
|
||||
// @Tags accessList
|
||||
// @Summary Удалить список доступных методов для приложения
|
||||
// @Description Удаляет заданный список методов для приложения
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListDeleteListRequest false "тело запроса"
|
||||
// @Success 200 {object} any
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /access_list/delete_list [POST]
|
||||
func (c AccessList) DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error {
|
||||
err := c.service.DeleteList(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.AppId),
|
||||
err,
|
||||
)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SecureService interface {
|
||||
|
||||
@@ -10,6 +10,19 @@ definitions:
|
||||
errorMessage:
|
||||
type: string
|
||||
type: object
|
||||
domain.AccessListDeleteListRequest:
|
||||
properties:
|
||||
appId:
|
||||
type: integer
|
||||
methods:
|
||||
items:
|
||||
type: string
|
||||
minItems: 1
|
||||
type: array
|
||||
required:
|
||||
- appId
|
||||
- methods
|
||||
type: object
|
||||
domain.AccessListSetListRequest:
|
||||
properties:
|
||||
appId:
|
||||
@@ -389,6 +402,34 @@ info:
|
||||
title: isp-system-service
|
||||
version: 1.0.0
|
||||
paths:
|
||||
/access_list/delete_list:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Удаляет заданный список методов для приложения
|
||||
parameters:
|
||||
- description: тело запроса
|
||||
in: body
|
||||
name: body
|
||||
schema:
|
||||
$ref: '#/definitions/domain.AccessListDeleteListRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema: {}
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Удалить список доступных методов для приложения
|
||||
tags:
|
||||
- accessList
|
||||
/access_list/get_by_id:
|
||||
post:
|
||||
consumes:
|
||||
|
||||
@@ -20,3 +20,8 @@ type MethodInfo struct {
|
||||
Method string
|
||||
Value bool
|
||||
}
|
||||
|
||||
type AccessListDeleteListRequest struct {
|
||||
AppId int `validate:"required"`
|
||||
Methods []string `validate:"required,min=1"`
|
||||
}
|
||||
@@ -7,7 +7,7 @@ require (
|
||||
github.com/jackc/pgx/v5 v5.7.4
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/txix-open/isp-kit v1.48.1
|
||||
github.com/txix-open/isp-kit v1.51.0
|
||||
github.com/txix-open/jsonschema v1.3.0
|
||||
google.golang.org/grpc v1.72.0
|
||||
)
|
||||
|
||||
@@ -144,10 +144,10 @@ github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgj
|
||||
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
|
||||
github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA=
|
||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
||||
github.com/txix-open/grmq v1.8.0 h1:YXTruBap7EQZ6WNOhjoFqx/XBYMBhgeYM4mzNkX+bzU=
|
||||
github.com/txix-open/grmq v1.8.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
|
||||
github.com/txix-open/isp-kit v1.48.1 h1:LZGZSpjUIaUfUQOGOHgRm9Q977su/C/rv3bI4w+x9iw=
|
||||
github.com/txix-open/isp-kit v1.48.1/go.mod h1:qp0pbpsUqaAKhYGKGArYnBd0u7UBYuh561Q4MFkEqgs=
|
||||
github.com/txix-open/grmq v1.8.1 h1:bcPLuYZXJ+1h9D3w7JYzUTypnQsw9XAT0Ftl/Fu+cZA=
|
||||
github.com/txix-open/grmq v1.8.1/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
|
||||
github.com/txix-open/isp-kit v1.51.0 h1:sSDs/M5EaAiIJGbefRprbZH2GgCfdjwgpUV94NWd73A=
|
||||
github.com/txix-open/isp-kit v1.51.0/go.mod h1:OkscabRkpFGjUOFrbPM7yTKD/Br2/iv5/PWr/T2Jtd4=
|
||||
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
|
||||
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
"github.com/txix-open/isp-kit/shutdown"
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/routes"
|
||||
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
"github.com/txix-open/isp-kit/shutdown"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type AccessList struct {
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
|
||||
+3
-2
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
|
||||
+7
-1
@@ -1,10 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"isp-system-service/controller"
|
||||
|
||||
"github.com/txix-open/isp-kit/cluster"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||
"isp-system-service/controller"
|
||||
)
|
||||
|
||||
type Controllers struct {
|
||||
@@ -73,6 +74,11 @@ func accessListCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
Inner: true,
|
||||
Handler: c.AccessList.SetList,
|
||||
},
|
||||
{
|
||||
Path: "system/access_list/delete_list",
|
||||
Inner: true,
|
||||
Handler: c.AccessList.DeleteList,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
type AccessListRepo interface {
|
||||
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []string) error
|
||||
}
|
||||
|
||||
type AccessListSetOneTx interface {
|
||||
@@ -155,3 +156,15 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
|
||||
return methodInfos, nil
|
||||
}
|
||||
|
||||
func (s AccessList) DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error {
|
||||
_, err := s.appRepo.GetApplicationById(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
err = s.accessListRepo.DeleteAccessList(ctx, req.AppId, req.Methods)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete access_list")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+2
-1
@@ -3,9 +3,10 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/repository"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
"github.com/txix-open/isp-kit/test/fake"
|
||||
"github.com/txix-open/isp-kit/test/grpct"
|
||||
)
|
||||
|
||||
func TestAccessListSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &AccessListSuite{})
|
||||
}
|
||||
|
||||
type AccessListSuite struct {
|
||||
suite.Suite
|
||||
test *test.Test
|
||||
testDb *dbt.TestDb
|
||||
api *client.Client
|
||||
accessListRepo repository.AccessList
|
||||
appId int
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) SetupTest() {
|
||||
s.test, _ = test.New(s.T())
|
||||
|
||||
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
|
||||
|
||||
locator := assembly.NewLocator(s.testDb, s.test.Logger())
|
||||
config := locator.Config(conf.Remote{})
|
||||
_, s.api = grpct.TestServer(s.test, config.Handler)
|
||||
s.accessListRepo = repository.NewAccessList(s.testDb)
|
||||
|
||||
createdDomain, err := repository.NewDomain(s.testDb).CreateDomain(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
1,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
appGroup, err := repository.NewAppGroup(s.testDb).CreateAppGroup(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
createdDomain.Id,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.appId = fake.It[int]()
|
||||
|
||||
_, err = repository.NewApplication(s.testDb).CreateApplication(
|
||||
s.T().Context(),
|
||||
s.appId,
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
appGroup.Id,
|
||||
domain.ApplicationSystemType,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestGetById_HappyPath() {
|
||||
expectedAccessList := []entity.AccessList{
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: false,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
}
|
||||
|
||||
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), expectedAccessList)
|
||||
s.Require().NoError(err)
|
||||
|
||||
req := domain.Identity{
|
||||
Id: s.appId,
|
||||
}
|
||||
var accessList []domain.MethodInfo
|
||||
err = s.api.Invoke("system/access_list/get_by_id").
|
||||
JsonRequestBody(&req).
|
||||
JsonResponseBody(&accessList).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(accessList, len(expectedAccessList))
|
||||
|
||||
actualAccessList := s.convertAccessList(accessList)
|
||||
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestSetOne_HappyPath() {
|
||||
expectedAccessList := []entity.AccessList{
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: false,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
}
|
||||
|
||||
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), expectedAccessList)
|
||||
s.Require().NoError(err)
|
||||
|
||||
req := domain.AccessListSetOneRequest{
|
||||
AppId: s.appId,
|
||||
Method: expectedAccessList[0].Method,
|
||||
Value: true,
|
||||
}
|
||||
err = s.api.Invoke("system/access_list/set_one").
|
||||
JsonRequestBody(&req).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
|
||||
s.Require().NoError(err)
|
||||
|
||||
for i := range expectedAccessList {
|
||||
expectedAccessList[i].Value = true
|
||||
}
|
||||
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestSetList_HappyPath() {
|
||||
req := domain.AccessListSetListRequest{
|
||||
AppId: s.appId,
|
||||
Methods: []domain.MethodInfo{
|
||||
{
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/access_list/set_list").
|
||||
JsonRequestBody(&req).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(actualAccessList, len(req.Methods))
|
||||
|
||||
expectedAccessList := s.convertAccessList(req.Methods)
|
||||
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestDeleteList_HappyPath() {
|
||||
accessList := []entity.AccessList{
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: false,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
}
|
||||
|
||||
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), accessList)
|
||||
s.Require().NoError(err)
|
||||
|
||||
req := domain.AccessListDeleteListRequest{
|
||||
AppId: s.appId,
|
||||
Methods: []string{
|
||||
accessList[0].Method,
|
||||
accessList[1].Method,
|
||||
},
|
||||
}
|
||||
err = s.api.Invoke("system/access_list/delete_list").
|
||||
JsonRequestBody(&req).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(actualAccessList, 1)
|
||||
s.Require().Equal(accessList[2], actualAccessList[0])
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) convertAccessList(methods []domain.MethodInfo) []entity.AccessList {
|
||||
converted := make([]entity.AccessList, 0, len(methods))
|
||||
for _, method := range methods {
|
||||
converted = append(converted, entity.AccessList{
|
||||
AppId: s.appId,
|
||||
Method: method.Method,
|
||||
Value: method.Value,
|
||||
})
|
||||
}
|
||||
return converted
|
||||
}
|
||||
+18
-20
@@ -12,7 +12,6 @@ import (
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
@@ -27,14 +26,13 @@ func TestSecureSuite(t *testing.T) {
|
||||
|
||||
type SecureSuite struct {
|
||||
suite.Suite
|
||||
test *test.Test
|
||||
require *require.Assertions
|
||||
testDb *dbt.TestDb
|
||||
api *client.Client
|
||||
test *test.Test
|
||||
testDb *dbt.TestDb
|
||||
api *client.Client
|
||||
}
|
||||
|
||||
func (s *SecureSuite) SetupSuite() {
|
||||
s.test, s.require = test.New(s.T())
|
||||
s.test, _ = test.New(s.T())
|
||||
|
||||
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
|
||||
|
||||
@@ -66,8 +64,8 @@ func (s *SecureSuite) TestAuthenticate_Success() {
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: true,
|
||||
ErrorReason: "",
|
||||
AuthData: &domain.AuthData{
|
||||
@@ -87,8 +85,8 @@ func (s *SecureSuite) TestAuthenticate_NotFound() {
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenNotFound.Error(),
|
||||
AuthData: nil,
|
||||
@@ -107,8 +105,8 @@ func (s *SecureSuite) TestAuthenticate_NotExpired() {
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: true,
|
||||
ErrorReason: "",
|
||||
AuthData: &domain.AuthData{
|
||||
@@ -132,8 +130,8 @@ func (s *SecureSuite) TestAuthenticate_Expired() {
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenExpired.Error(),
|
||||
AuthData: nil,
|
||||
@@ -155,8 +153,8 @@ func (s *SecureSuite) TestAuthorize_Success_True() {
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthorizeResponse{
|
||||
Authorized: true,
|
||||
}, result)
|
||||
}
|
||||
@@ -176,8 +174,8 @@ func (s *SecureSuite) TestAuthorize_Success_False() {
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthorizeResponse{
|
||||
Authorized: false,
|
||||
}, result)
|
||||
}
|
||||
@@ -191,8 +189,8 @@ func (s *SecureSuite) TestAuthorize_NotFound() {
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthorizeResponse{
|
||||
Authorized: false,
|
||||
}, result)
|
||||
}
|
||||
Reference in new issue
Block a user