github.com/hernad/nomad@v1.6.112/ui/tests/unit/abilities/token-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 /* eslint-disable ember/avoid-leaking-state-in-ember-objects */ 7 import { module, test } from 'qunit'; 8 import { setupTest } from 'ember-qunit'; 9 import Service from '@ember/service'; 10 import setupAbility from 'nomad-ui/tests/helpers/setup-ability'; 11 12 module('Unit | Ability | token', function (hooks) { 13 setupTest(hooks); 14 setupAbility('token')(hooks); 15 16 test('A non-management user can do nothing with tokens', function (assert) { 17 const mockToken = Service.extend({ 18 aclEnabled: true, 19 selfToken: { type: 'client' }, 20 }); 21 this.owner.register('service:token', mockToken); 22 assert.notOk(this.ability.canRead); 23 assert.notOk(this.ability.canList); 24 assert.notOk(this.ability.canWrite); 25 assert.notOk(this.ability.canUpdate); 26 assert.notOk(this.ability.canDestroy); 27 }); 28 29 test('A management user can do everything with tokens', function (assert) { 30 const mockToken = Service.extend({ 31 aclEnabled: true, 32 selfToken: { type: 'management' }, 33 }); 34 this.owner.register('service:token', mockToken); 35 assert.ok(this.ability.canRead); 36 assert.ok(this.ability.canList); 37 assert.ok(this.ability.canWrite); 38 assert.ok(this.ability.canUpdate); 39 assert.ok(this.ability.canDestroy); 40 }); 41 42 test('A non-ACL agent (bypassAuthorization) does not allow anything', function (assert) { 43 const mockToken = Service.extend({ 44 aclEnabled: false, 45 }); 46 this.owner.register('service:token', mockToken); 47 assert.notOk(this.ability.canRead); 48 assert.notOk(this.ability.canList); 49 assert.notOk(this.ability.canWrite); 50 assert.notOk(this.ability.canUpdate); 51 assert.notOk(this.ability.canDestroy); 52 }); 53 });