Skip to content

Commit

Permalink
test: Slightly shorten the code of integration_test.go
Browse files Browse the repository at this point in the history
Added function `formAllowRecord` to create `apiserver.Record`.

Signed-off-by: Tatiana Nesterenko <[email protected]>
  • Loading branch information
tatiana-nspcc committed Aug 22, 2024
1 parent 38b9082 commit 996a8da
Showing 1 changed file with 24 additions and 81 deletions.
105 changes: 24 additions & 81 deletions cmd/neofs-rest-gw/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ func formRestrictRecord(op apiserver.Operation) apiserver.Record {
}}}
}

func formAllowRecord(op apiserver.Operation) apiserver.Record {
return apiserver.Record{
Operation: op,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}}}
}

func authTokens(ctx context.Context, t *testing.T) {
bearers := []apiserver.Bearer{
{
Expand Down Expand Up @@ -1795,15 +1806,9 @@ func restObjectUploadCookie(ctx context.Context, t *testing.T, clientPool *pool.
}
func restObjectUploadInt(ctx context.Context, t *testing.T, clientPool *pool.Pool, cnrID cid.ID, signer user.Signer, cookie bool) {
bt := apiserver.Bearer{
Object: []apiserver.Record{{
Operation: apiserver.OperationPUT,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
}},
Object: []apiserver.Record{
formAllowRecord(apiserver.OperationPUT),
},
}
bt.Object = append(bt.Object, getRestrictBearerRecords()...)

Expand Down Expand Up @@ -1885,15 +1890,9 @@ func restNewObjectUploadWC(ctx context.Context, t *testing.T, clientPool *pool.P
}
func restNewObjectUploadInt(ctx context.Context, t *testing.T, clientPool *pool.Pool, cnrID cid.ID, signer user.Signer, cookie bool, walletConnect bool) {
bt := apiserver.Bearer{
Object: []apiserver.Record{{
Operation: apiserver.OperationPUT,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
}},
Object: []apiserver.Record{
formAllowRecord(apiserver.OperationPUT),
},
}
bt.Object = append(bt.Object, getRestrictBearerRecords()...)

Expand Down Expand Up @@ -1973,24 +1972,8 @@ func restNewObjectUploadInt(ctx context.Context, t *testing.T, clientPool *pool.
func restNewObjectHead(ctx context.Context, t *testing.T, p *pool.Pool, ownerID *user.ID, cnrID cid.ID, signer user.Signer, walletConnect bool) {
bearer := apiserver.Bearer{
Object: []apiserver.Record{
{
Operation: apiserver.OperationHEAD,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
},
{
Operation: apiserver.OperationRANGE,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
},
formAllowRecord(apiserver.OperationHEAD),
formAllowRecord(apiserver.OperationRANGE),
},
}
bearer.Object = append(bearer.Object, getRestrictBearerRecords()...)
Expand Down Expand Up @@ -2144,33 +2127,9 @@ func restNewObjectHead(ctx context.Context, t *testing.T, p *pool.Pool, ownerID
func restNewObjectHeadByAttribute(ctx context.Context, t *testing.T, p *pool.Pool, ownerID *user.ID, cnrID cid.ID, signer user.Signer, walletConnect bool) {
bearer := apiserver.Bearer{
Object: []apiserver.Record{
{
Operation: apiserver.OperationHEAD,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
},
{
Operation: apiserver.OperationRANGE,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
},
{
Operation: apiserver.OperationSEARCH,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
},
formAllowRecord(apiserver.OperationHEAD),
formAllowRecord(apiserver.OperationRANGE),
formAllowRecord(apiserver.OperationSEARCH),
},
}
bearer.Object = append(bearer.Object, getRestrictBearerRecords()...)
Expand Down Expand Up @@ -2322,24 +2281,8 @@ func restNewObjectHeadByAttribute(ctx context.Context, t *testing.T, p *pool.Poo
func restNewObjectGetByAttribute(ctx context.Context, t *testing.T, p *pool.Pool, ownerID *user.ID, cnrID cid.ID, signer user.Signer, walletConnect bool) {
bearer := apiserver.Bearer{
Object: []apiserver.Record{
{
Operation: apiserver.OperationGET,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
},
{
Operation: apiserver.OperationSEARCH,
Action: apiserver.ALLOW,
Filters: []apiserver.Filter{},
Targets: []apiserver.Target{{
Role: apiserver.OTHERS,
Keys: []string{},
}},
},
formAllowRecord(apiserver.OperationGET),
formAllowRecord(apiserver.OperationSEARCH),
},
}
bearer.Object = append(bearer.Object, getRestrictBearerRecords()...)
Expand Down

0 comments on commit 996a8da

Please sign in to comment.