Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/sdk-api/src/bitgoAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ export class BitGoAPI implements BitGoBase {
req.isV2Authenticated = true;
req.authenticationToken = this._token ?? (strategyAuthenticated ? 'strategy-authenticated' : undefined);
// some of the older tokens appear to be only 40 characters long
if ((this._token && this._token.length !== 67 && this._token.indexOf('v2x') !== 0) || req.forceV1Auth) {
if (this._token && ((this._token.length !== 67 && this._token.indexOf('v2x') !== 0) || req.forceV1Auth)) {
// use the old method
req.isV2Authenticated = false;

Expand Down
42 changes: 42 additions & 0 deletions modules/sdk-api/test/unit/bitgoAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,3 +1192,45 @@ describe('wallets() v1 facade', function () {
wallets.resendShareInvite.should.be.a.Function();
});
});

describe('undefined accessToken in testnet (WCI-1213)', function () {
const ROOT = 'https://app.bitgo-test.com';

afterEach(function () {
nock.cleanAll();
});

it('does not send "Bearer undefined" when accessToken is undefined (no forceV1Auth)', async function () {
const bitgo = new BitGoAPI({ env: 'test', accessToken: undefined });

let receivedAuthHeader: string | null = null;
nock(ROOT)
.post('/api/auth/v1/session')
.reply(function (uri, body) {
receivedAuthHeader = this.req.headers['authorization']?.[0] ?? null;
return [200, { user: { username: 'test@example.com' }, access_token: 'v2xtoken' }];
});

await bitgo.authenticate({ username: 'test@example.com', password: 'pw', otp: '000000' });

// With no token set, the v1 path must not be entered — so no 'Bearer undefined'
assert.notStrictEqual(receivedAuthHeader, 'Bearer undefined');
});

it('does not send "Bearer undefined" when accessToken is undefined and forceV1Auth is set', async function () {
const bitgo = new BitGoAPI({ env: 'test', accessToken: undefined });

let receivedAuthHeader: string | null = null;
nock(ROOT)
.post('/api/auth/v1/session')
.reply(function (uri, body) {
receivedAuthHeader = this.req.headers['authorization']?.[0] ?? null;
return [200, { user: { username: 'test@example.com' }, access_token: 'v2xtoken' }];
});

await bitgo.authenticate({ username: 'test@example.com', password: 'pw', otp: '000000', forceV1Auth: true });

// forceV1Auth must not bypass the token guard — header must not be 'Bearer undefined'
assert.notStrictEqual(receivedAuthHeader, 'Bearer undefined');
});
});
Loading