github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/unit/abilities/client-test.js (about)

     1  /* eslint-disable ember/avoid-leaking-state-in-ember-objects */
     2  import { module, test } from 'qunit';
     3  import { setupTest } from 'ember-qunit';
     4  import Service from '@ember/service';
     5  import setupAbility from 'nomad-ui/tests/helpers/setup-ability';
     6  
     7  module('Unit | Ability | client', function(hooks) {
     8    setupTest(hooks);
     9    setupAbility('client')(hooks);
    10  
    11    test('it permits client write when ACLs are disabled', function(assert) {
    12      const mockToken = Service.extend({
    13        aclEnabled: false,
    14      });
    15      this.owner.register('service:token', mockToken);
    16  
    17      assert.ok(this.ability.canWrite);
    18    });
    19  
    20    test('it permits client write for management tokens', function(assert) {
    21      const mockToken = Service.extend({
    22        aclEnabled: true,
    23        selfToken: { type: 'management' },
    24      });
    25      this.owner.register('service:token', mockToken);
    26  
    27      assert.ok(this.ability.canWrite);
    28    });
    29  
    30    test('it permits client write for tokens with a policy that has node-write', function(assert) {
    31      const mockToken = Service.extend({
    32        aclEnabled: true,
    33        selfToken: { type: 'client' },
    34        selfTokenPolicies: [
    35          {
    36            rulesJSON: {
    37              Node: {
    38                Policy: 'write',
    39              },
    40            },
    41          },
    42        ],
    43      });
    44      this.owner.register('service:token', mockToken);
    45  
    46      assert.ok(this.ability.canWrite);
    47    });
    48  
    49    test('it permits client write for tokens with a policy that allows write and another policy that disallows it', function(assert) {
    50      const mockToken = Service.extend({
    51        aclEnabled: true,
    52        selfToken: { type: 'client' },
    53        selfTokenPolicies: [
    54          {
    55            rulesJSON: {
    56              Node: {
    57                Policy: 'write',
    58              },
    59            },
    60          },
    61          {
    62            rulesJSON: {
    63              Node: {
    64                Policy: 'read',
    65              },
    66            },
    67          },
    68        ],
    69      });
    70      this.owner.register('service:token', mockToken);
    71  
    72      assert.ok(this.ability.canWrite);
    73    });
    74  
    75    test('it blocks client write for tokens with a policy that does not allow node-write', function(assert) {
    76      const mockToken = Service.extend({
    77        aclEnabled: true,
    78        selfToken: { type: 'client' },
    79        selfTokenPolicies: [
    80          {
    81            rulesJSON: {
    82              Node: {
    83                Policy: 'read',
    84              },
    85            },
    86          },
    87        ],
    88      });
    89      this.owner.register('service:token', mockToken);
    90  
    91      assert.notOk(this.ability.canWrite);
    92    });
    93  });