Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: faye doesn't use custom stuff passed it #505

Merged
merged 1 commit into from
Dec 15, 2021
Merged
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
22 changes: 5 additions & 17 deletions src/status/streamingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ export namespace StreamingClient {
public handshakeTimeout: Duration;
public channel: string;
public streamingImpl: StreamingClientIfc;
private envDep: Env;

/**
* Constructor for DefaultStreamingOptions
Expand All @@ -528,6 +527,10 @@ export namespace StreamingClient {
* @see {@link StatusResult}
*/
public constructor(org: Org, channel: string, streamProcessor: StreamProcessor, envDep: Env = env) {
if (envDep) {
const logger = Logger.childFromRoot('StreamingClient');
logger.warn('envDep is deprecated');
}
if (!streamProcessor) {
throw new SfdxError('Missing stream processor', 'MissingArg');
}
Expand All @@ -540,7 +543,6 @@ export namespace StreamingClient {
throw new SfdxError('Missing streaming channel', 'MissingArg');
}

this.envDep = envDep;
this.org = org;
this.apiVersion = org.getConnection().getApiVersion();

Expand All @@ -558,21 +560,7 @@ export namespace StreamingClient {
this.handshakeTimeout = StreamingClient.DefaultOptions.DEFAULT_HANDSHAKE_TIMEOUT;
this.streamingImpl = {
getCometClient: (url: string): CometClient => {
const x = this.envDep.getString(StreamingClient.DefaultOptions.SFDX_ENABLE_FAYE_COOKIES_ALLOW_ALL_PATHS);
return new Faye.Client(url, {
// This parameter ensures all cookies regardless of path are included in subsequent requests. Otherwise
// only cookies with the path "/" and "/cometd" are known to be included.
// if SFDX_ENABLE_FAYE_COOKIES_ALLOW_ALL_PATHS is *not* set the default to true.
cookiesAllowAllPaths:
x === undefined
? true
: this.envDep.getBoolean(StreamingClient.DefaultOptions.SFDX_ENABLE_FAYE_COOKIES_ALLOW_ALL_PATHS),
// WARNING - The allows request/response exchanges to be written to the log instance which includes
// header and cookie information.
enableRequestResponseLogging: this.envDep.getBoolean(
StreamingClient.DefaultOptions.SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING
),
});
return new Faye.Client(url);
},
setLogger: (logLine: (message: string) => void): void => {
Faye.logger = {};
Expand Down
60 changes: 1 addition & 59 deletions test/unit/status/streamingClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import { spyMethod, stubMethod } from '@salesforce/ts-sinon';
import { expect } from 'chai';
import { SinonSpyCall } from 'sinon';
import { Duration, Env } from '@salesforce/kit';
import { Duration } from '@salesforce/kit';
import { get, JsonMap } from '@salesforce/ts-types';
import * as Faye from 'faye';
import { StatusResult } from '../../../src/status/client';
import { CometClient, StreamingClient } from '../../../src/status/streamingClient';

Expand Down Expand Up @@ -104,63 +103,6 @@ describe('streaming client tests', () => {
};
};

let env: Env;

beforeEach(() => {
env = new Env({});
});

function getStub(org: Org): sinon.SinonStub {
const stub = $$.SANDBOX.stub(Faye, 'Client');

const options: StreamingClient.Options = new StreamingClient.DefaultOptions(
org,
MOCK_TOPIC,
streamProcessor,
env
);

options.streamingImpl.getCometClient('http://example.com');
return stub;
}

it('expect default options', async () => {
const org: Org = await Org.create({ aliasOrUsername: username });
const stub = getStub(org);

expect(stub.args[0]).to.not.be.undefined;
expect(stub.args[0]).to.have.length(2);
const clientOptions = stub.args[0][1];
expect(clientOptions).to.have.property('cookiesAllowAllPaths', true);
expect(clientOptions).to.have.property('enableRequestResponseLogging', false);
});

it('set enableRequestResponseLogging', async () => {
env.setBoolean(StreamingClient.DefaultOptions.SFDX_ENABLE_FAYE_REQUEST_RESPONSE_LOGGING, true);

const org: Org = await Org.create({ aliasOrUsername: username });
const stub = getStub(org);

expect(stub.args[0]).to.not.be.undefined;
expect(stub.args[0]).to.have.length(2);

const clientOptions = stub.args[0][1];
expect(clientOptions).to.have.property('enableRequestResponseLogging', true);
});

it('unset cookiesAllowAllPaths', async () => {
env.setBoolean(StreamingClient.DefaultOptions.SFDX_ENABLE_FAYE_COOKIES_ALLOW_ALL_PATHS, true);

const org: Org = await Org.create({ aliasOrUsername: username });
const stub = getStub(org);

expect(stub.args[0]).to.not.be.undefined;
expect(stub.args[0]).to.have.length(2);

const clientOptions = stub.args[0][1];
expect(clientOptions).to.have.property('cookiesAllowAllPaths', true);
});

it('bogus apiVersion', async () => {
const org: Org = await Org.create({ aliasOrUsername: username });

Expand Down