diff --git a/lib/auth/Vault.ts b/lib/auth/Vault.ts index 776f62145..33097feae 100644 --- a/lib/auth/Vault.ts +++ b/lib/auth/Vault.ts @@ -1,6 +1,7 @@ import { Logger } from 'werelogs'; import errors from '../errors'; import AuthInfo, { AccountInfos, AuthInfoType, AuthorizationResults, AuthV4Results } from './AuthInfo'; +import RequestContext from '../policyEvaluator/RequestContext'; /** vaultSignatureCb parses message from Vault and instantiates * @param err - error from vault @@ -86,6 +87,15 @@ export type AuthV4RequestParams = { }; }; +export type AuthenticationOptions = { + algo?: 'sha1' | 'sha256'; // for v2 auth + reqUid?: string; + get?: boolean; + logger?: Logger; + requestContext?: RequestContext; + securityToken?: string; +}; + /** * Class that provides common authentication methods against different * authentication backends. @@ -196,7 +206,7 @@ export default class Vault { params: AuthV4RequestParams, requestContexts: any[] | null, callback: (err: Error | null, data?: any) => void, - options: any = {}, + options: AuthenticationOptions = {}, ) { params.log.debug('authenticating V4 request'); let serializedRCs: any; diff --git a/tests/unit/auth/auth.spec.js b/tests/unit/auth/auth.spec.js index ebeb11f2f..a993888b6 100644 --- a/tests/unit/auth/auth.spec.js +++ b/tests/unit/auth/auth.spec.js @@ -6,7 +6,7 @@ const Vault = require('../../../lib/auth/Vault').default; const assert = require('assert'); const sinon = require('sinon'); -describe.only('auth.doAuth', () => { +describe('auth.doAuth', () => { let request; let log; let cb; @@ -19,7 +19,7 @@ describe.only('auth.doAuth', () => { const xAMZcontentSha256 = '771df8abbecb2265e9724e5dc4510dcc160' + '60c0513ae669baf35b255d465b63f'; const host = 'localhost:8000'; - const xAMZdate = '20270208T201405Z'; + const xAmzDate = '2027-02-08T20:14:05Z'; const authorization = 'AWS4-HMAC-SHA256 Credential=accessKey1/20270208' + '/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;' + 'x-amz-date, Signature=abed924c06abf8772c670064d22eacd6ccb85c06befa15f' + @@ -27,7 +27,7 @@ describe.only('auth.doAuth', () => { const headers = { host, authorization, - 'x-amz-date': xAMZdate, + 'x-amz-date': '20270208T201405Z', 'x-amz-content-sha256': xAMZcontentSha256, }; @@ -89,7 +89,7 @@ describe.only('auth.doAuth', () => { query: {}, }; // Mock the v4 authentication method - const clock = fakeTimers.install({ now: new Date('2027-02-08T20:14:05Z').getTime() }); + const clock = fakeTimers.install({ now: new Date(xAmzDate).getTime() }); const authenticateV4RequestStub = sandbox.stub(vault, 'authenticateV4Request'); @@ -122,7 +122,7 @@ describe.only('auth.doAuth', () => { query: {}, }; // Mock the v4 authentication method - const clock = fakeTimers.install({ now: new Date('2027-02-08T20:14:05Z').getTime() }); + const clock = fakeTimers.install({ now: new Date(xAmzDate).getTime() }); mockOptions = { get: true }; const authenticateV4RequestStub = sandbox.stub(vault, 'authenticateV4Request');