Skip to content

Commit

Permalink
Post reviews fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Mar 5, 2025
1 parent da106bd commit 0deb34b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion lib/auth/Vault.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/auth/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,15 +19,15 @@ 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' +
'4a789b0bae19307bc';
const headers = {
host,
authorization,
'x-amz-date': xAMZdate,
'x-amz-date': '20270208T201405Z',
'x-amz-content-sha256': xAMZcontentSha256,
};

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 0deb34b

Please sign in to comment.