open-vault/ui/tests/unit/serializers/policy-test.js

73 lines
5.7 KiB
JavaScript
Raw Normal View History

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
2018-04-03 14:16:57 +00:00
module('Unit | Serializer | policy', function(hooks) {
setupTest(hooks);
2018-04-03 14:16:57 +00:00
const POLICY_LIST_RESPONSE = {
2018-04-03 14:16:57 +00:00
keys: ['default', 'root'],
policies: ['default', 'root'],
request_id: '3a6a3d67-dc3b-a086-2fc7-902bdc4dec3a',
lease_id: '',
renewable: false,
lease_duration: 0,
data: {
keys: ['default', 'root'],
policies: ['default', 'root'],
},
wrap_info: null,
warnings: null,
auth: null,
};
2018-04-03 14:16:57 +00:00
const EMBER_DATA_EXPECTS_FOR_POLICY_LIST = [{ name: 'default' }, { name: 'root' }];
2018-04-03 14:16:57 +00:00
const POLICY_SHOW_RESPONSE = {
2018-04-03 14:16:57 +00:00
name: 'default',
rules:
'\n# Allow tokens to look up their own properties\npath "auth/token/lookup-self" {\n capabilities = ["read"]\n}\n\n# Allow tokens to renew themselves\npath "auth/token/renew-self" {\n capabilities = ["update"]\n}\n\n# Allow tokens to revoke themselves\npath "auth/token/revoke-self" {\n capabilities = ["update"]\n}\n\n# Allow a token to look up its own capabilities on a path\npath "sys/capabilities-self" {\n capabilities = ["update"]\n}\n\n# Allow a token to renew a lease via lease_id in the request body\npath "sys/renew" {\n capabilities = ["update"]\n}\n\n# Allow a token to manage its own cubbyhole\npath "cubbyhole/*" {\n capabilities = ["create", "read", "update", "delete", "list"]\n}\n\n# Allow a token to list its cubbyhole (not covered by the splat above)\npath "cubbyhole" {\n capabilities = ["list"]\n}\n\n# Allow a token to wrap arbitrary values in a response-wrapping token\npath "sys/wrapping/wrap" {\n capabilities = ["update"]\n}\n\n# Allow a token to look up the creation time and TTL of a given\n# response-wrapping token\npath "sys/wrapping/lookup" {\n capabilities = ["update"]\n}\n\n# Allow a token to unwrap a response-wrapping token. This is a convenience to\n# avoid client token swapping since this is also part of the response wrapping\n# policy.\npath "sys/wrapping/unwrap" {\n capabilities = ["update"]\n}\n',
request_id: '890eabf8-d418-07af-f978-928d328a7e64',
lease_id: '',
renewable: false,
lease_duration: 0,
data: {
name: 'default',
rules:
'\n# Allow tokens to look up their own properties\npath "auth/token/lookup-self" {\n capabilities = ["read"]\n}\n\n# Allow tokens to renew themselves\npath "auth/token/renew-self" {\n capabilities = ["update"]\n}\n\n# Allow tokens to revoke themselves\npath "auth/token/revoke-self" {\n capabilities = ["update"]\n}\n\n# Allow a token to look up its own capabilities on a path\npath "sys/capabilities-self" {\n capabilities = ["update"]\n}\n\n# Allow a token to renew a lease via lease_id in the request body\npath "sys/renew" {\n capabilities = ["update"]\n}\n\n# Allow a token to manage its own cubbyhole\npath "cubbyhole/*" {\n capabilities = ["create", "read", "update", "delete", "list"]\n}\n\n# Allow a token to list its cubbyhole (not covered by the splat above)\npath "cubbyhole" {\n capabilities = ["list"]\n}\n\n# Allow a token to wrap arbitrary values in a response-wrapping token\npath "sys/wrapping/wrap" {\n capabilities = ["update"]\n}\n\n# Allow a token to look up the creation time and TTL of a given\n# response-wrapping token\npath "sys/wrapping/lookup" {\n capabilities = ["update"]\n}\n\n# Allow a token to unwrap a response-wrapping token. This is a convenience to\n# avoid client token swapping since this is also part of the response wrapping\n# policy.\npath "sys/wrapping/unwrap" {\n capabilities = ["update"]\n}\n',
},
wrap_info: null,
warnings: null,
auth: null,
};
2018-04-03 14:16:57 +00:00
const EMBER_DATA_EXPECTS_FOR_POLICY_SHOW = {
name: 'default',
rules:
'\n# Allow tokens to look up their own properties\npath "auth/token/lookup-self" {\n capabilities = ["read"]\n}\n\n# Allow tokens to renew themselves\npath "auth/token/renew-self" {\n capabilities = ["update"]\n}\n\n# Allow tokens to revoke themselves\npath "auth/token/revoke-self" {\n capabilities = ["update"]\n}\n\n# Allow a token to look up its own capabilities on a path\npath "sys/capabilities-self" {\n capabilities = ["update"]\n}\n\n# Allow a token to renew a lease via lease_id in the request body\npath "sys/renew" {\n capabilities = ["update"]\n}\n\n# Allow a token to manage its own cubbyhole\npath "cubbyhole/*" {\n capabilities = ["create", "read", "update", "delete", "list"]\n}\n\n# Allow a token to list its cubbyhole (not covered by the splat above)\npath "cubbyhole" {\n capabilities = ["list"]\n}\n\n# Allow a token to wrap arbitrary values in a response-wrapping token\npath "sys/wrapping/wrap" {\n capabilities = ["update"]\n}\n\n# Allow a token to look up the creation time and TTL of a given\n# response-wrapping token\npath "sys/wrapping/lookup" {\n capabilities = ["update"]\n}\n\n# Allow a token to unwrap a response-wrapping token. This is a convenience to\n# avoid client token swapping since this is also part of the response wrapping\n# policy.\npath "sys/wrapping/unwrap" {\n capabilities = ["update"]\n}\n',
};
2018-04-03 14:16:57 +00:00
test('it transforms a list request payload', function(assert) {
let serializer = this.owner.lookup('serializer:policy');
2018-04-03 14:16:57 +00:00
let transformedPayload = serializer.normalizePolicies(POLICY_LIST_RESPONSE);
2018-04-03 14:16:57 +00:00
assert.deepEqual(
transformedPayload,
EMBER_DATA_EXPECTS_FOR_POLICY_LIST,
'transformed payload matches the expected payload'
);
});
2018-04-03 14:16:57 +00:00
test('it transforms a list request payload', function(assert) {
let serializer = this.owner.lookup('serializer:policy');
2018-04-03 14:16:57 +00:00
let transformedPayload = serializer.normalizePolicies(POLICY_SHOW_RESPONSE);
2018-04-03 14:16:57 +00:00
assert.deepEqual(
transformedPayload,
EMBER_DATA_EXPECTS_FOR_POLICY_SHOW,
'transformed payload matches the expected payload'
);
});
2018-04-03 14:16:57 +00:00
});