github.com/aminovpavel/nomad@v0.11.8/ui/tests/unit/abilities/client-test.js (about)

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