mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 02:02:43 +00:00
* fix: calculate expiration of all batch tokens to ensure expire warning banner is shown * fix: ensure allowExpiration doesn't get overridden * fix: set expirationCalcTS outside of calculateExpression * tests: verify expirationEpoch is calculated when only expiry_time is passed in * fix: calculate expireTime using expire_time if its passed in * tests: clean up auth tests * tests: organize batch token vs. service token tests into separate module * chore: update changelog * Update changelog/27479.txt Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> * fix: ensure tokens in test envs do not expire * cleanup: pull setExpiration settings into own method & add tests --------- Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
module('Unit | Service | auth', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.service = this.owner.lookup('service:auth');
|
|
});
|
|
|
|
module('#calculateExpiration', function () {
|
|
[
|
|
['#calculateExpiration w/ttl', { ttl: 30 }, 30],
|
|
['#calculateExpiration w/lease_duration', { lease_duration: 15 }, 15],
|
|
].forEach(([testName, response, ttlValue]) => {
|
|
test(testName, function (assert) {
|
|
const now = Date.now();
|
|
|
|
const resp = this.service.calculateExpiration(response, now);
|
|
|
|
assert.strictEqual(resp.ttl, ttlValue, 'returns the ttl');
|
|
assert.strictEqual(
|
|
resp.tokenExpirationEpoch,
|
|
now + ttlValue * 1e3,
|
|
'calculates expiration from ttl as epoch timestamp'
|
|
);
|
|
});
|
|
});
|
|
|
|
test('#calculateExpiration w/ expire_time', function (assert) {
|
|
const now = Date.now();
|
|
const expirationString = '2024-06-13T09:10:21-07:00';
|
|
const expectedExpirationEpoch = new Date(expirationString).getTime();
|
|
|
|
const resp = this.service.calculateExpiration(
|
|
{ ttl: 30, expire_time: '2024-06-13T09:10:21-07:00' },
|
|
now
|
|
);
|
|
|
|
assert.strictEqual(resp.ttl, 30, 'returns ttl');
|
|
assert.strictEqual(
|
|
resp.tokenExpirationEpoch,
|
|
expectedExpirationEpoch,
|
|
'calculates expiration from expire_time'
|
|
);
|
|
});
|
|
});
|
|
|
|
module('#setExpirationSettings', function () {
|
|
test('#setExpirationSettings for a renewable token', function (assert) {
|
|
const now = Date.now();
|
|
const ttl = 30;
|
|
const response = { ttl, renewable: true };
|
|
|
|
this.service.setExpirationSettings(response, now);
|
|
|
|
assert.false(this.service.allowExpiration, 'sets allowExpiration to false');
|
|
assert.strictEqual(this.service.expirationCalcTS, now, 'sets expirationCalcTS to now');
|
|
});
|
|
|
|
test('#setExpirationSettings for a non-renewable token', function (assert) {
|
|
const now = Date.now();
|
|
const ttl = 30;
|
|
const response = { ttl, renewable: false };
|
|
|
|
this.service.setExpirationSettings(response, now);
|
|
|
|
assert.true(this.service.allowExpiration, 'sets allowExpiration to true');
|
|
assert.strictEqual(this.service.expirationCalcTS, null, 'keeps expirationCalcTS as null');
|
|
});
|
|
});
|
|
});
|