|
| 1 | +// Copyright 2025 Democratized Data Foundation |
| 2 | +// |
| 3 | +// Use of this software is governed by the Business Source License |
| 4 | +// included in the file licenses/BSL.txt. |
| 5 | +// |
| 6 | +// As of the Change Date specified in that file, in accordance with |
| 7 | +// the Business Source License, use of this software will be governed |
| 8 | +// by the Apache License, Version 2.0, included in the file |
| 9 | +// licenses/APL.txt. |
| 10 | + |
| 11 | +package test_acp_aac |
| 12 | + |
| 13 | +import ( |
| 14 | + "testing" |
| 15 | + |
| 16 | + testUtils "github.com/sourcenetwork/defradb/tests/integration" |
| 17 | +) |
| 18 | + |
| 19 | +func TestAAC_GatesIndexDrop_AllowIfAuthorizedElseError(t *testing.T) { |
| 20 | + test := testUtils.TestCase{ |
| 21 | + Description: "admin acp correctly gates index drop operation, allow if authorized, otherwise error", |
| 22 | + Actions: []any{ |
| 23 | + // Starting with ACC, so only authorized user(s) can perform operations from here on out. |
| 24 | + testUtils.Close{}, |
| 25 | + testUtils.Start{ |
| 26 | + Identity: testUtils.ClientIdentity(1), |
| 27 | + EnableNAC: true, |
| 28 | + }, |
| 29 | + // Note: Doing setup steps after starting with aac enabled, otherwise the in-memory tests |
| 30 | + // will loose setup state when the restart happens (i.e. the restart that started aac). |
| 31 | + testUtils.SchemaUpdate{ |
| 32 | + Identity: testUtils.ClientIdentity(1), |
| 33 | + Schema: ` |
| 34 | + type User { |
| 35 | + name: String @index |
| 36 | + } |
| 37 | + `, |
| 38 | + }, |
| 39 | + // Note: Setup is now done, the test code that follows is what we want to assert. |
| 40 | + |
| 41 | + // We haven't authorized non-identities. So, this should error. |
| 42 | + testUtils.DropIndex{ |
| 43 | + Identity: testUtils.NoIdentity(), |
| 44 | + IndexName: "User_name_ASC", |
| 45 | + ExpectedError: "not authorized to perform operation", |
| 46 | + }, |
| 47 | + |
| 48 | + // Wrong user/identity will also not be authorized. |
| 49 | + testUtils.DropIndex{ |
| 50 | + Identity: testUtils.ClientIdentity(2), |
| 51 | + IndexName: "User_name_ASC", |
| 52 | + ExpectedError: "not authorized to perform operation", |
| 53 | + }, |
| 54 | + |
| 55 | + // This should work as the identity is authorized. |
| 56 | + testUtils.DropIndex{ |
| 57 | + Identity: testUtils.ClientIdentity(1), |
| 58 | + IndexName: "User_name_ASC", |
| 59 | + }, |
| 60 | + }, |
| 61 | + } |
| 62 | + |
| 63 | + testUtils.ExecuteTestCase(t, test) |
| 64 | +} |
0 commit comments