|
| 1 | +// Copyright 2020 The Casbin Authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import { newEnforcer } from '../src/index'; |
| 16 | +import { casbinJsGetPermissionForUser } from '../src/frontend'; |
| 17 | + |
| 18 | +test('TestCasbinJsGetPermissionForUser', async () => { |
| 19 | + const e = await newEnforcer('examples/rbac_model.conf', 'examples/rbac_with_hierarchy_policy.csv'); |
| 20 | + let permStr = await casbinJsGetPermissionForUser(e, 'alice'); |
| 21 | + let perm = JSON.parse(permStr); |
| 22 | + expect(perm['read']).toContain('data1'); |
| 23 | + expect(perm['write']).toContain('data1'); |
| 24 | + expect(perm['read']).toContain('data2'); |
| 25 | + expect(perm['write']).toContain('data2'); |
| 26 | + |
| 27 | + permStr = await casbinJsGetPermissionForUser(e, 'bob'); |
| 28 | + perm = JSON.parse(permStr); |
| 29 | + expect(perm['write']).toContain('data2'); |
| 30 | + expect(perm['write']).not.toContain('data1'); |
| 31 | + expect(perm['read']).not.toBeNull; |
| 32 | + expect(perm['rm_rf']).toBeNull; |
| 33 | +}); |
0 commit comments