Skip to content

Commit a4d5bb9

Browse files
author
Manuel Iglesias
authored
Merge branch 'master' into master
2 parents 71b178e + 4390e8e commit a4d5bb9

File tree

6 files changed

+81
-11
lines changed

6 files changed

+81
-11
lines changed

packages/core/src/Parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export default class Parser {
3535
storageConfig = {
3636
AWSS3: {
3737
bucket: config['aws_user_files_s3_bucket'],
38-
region: config['aws_user_files_s3_bucket_region']
38+
region: config['aws_user_files_s3_bucket_region'],
39+
dangerouslyConnectToHttpEndpointForTesting:
40+
config['aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing']
3941
}
4042
};
4143
} else {

packages/pubsub/__tests__/PubSub-unit-test.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ import * as Paho from '../src/vendor/paho-mqtt';
77

88
const pahoClientMockCache = {};
99

10+
const mockConnect = jest.fn((options) => {
11+
options.onSuccess();
12+
});
13+
1014
const pahoClientMock = jest.fn().mockImplementation((host, clientId) => {
1115
if (pahoClientMockCache[clientId]) {
1216
return pahoClientMockCache[clientId];
1317
}
1418

1519
var client = {} as any;
1620

17-
client.connect = jest.fn((options) => {
18-
options.onSuccess();
19-
});
21+
client.connect = mockConnect;
2022
client.send = jest.fn((topic, message) => {
2123
client.onMessageArrived({ destinationName: topic, payloadString: message });
2224
});
@@ -213,6 +215,32 @@ describe('PubSub', () => {
213215
});
214216
});
215217

218+
describe('MqttOverWSProvider local testing config', () => {
219+
test('ssl should be disabled in the case of local testing', async () => {
220+
mockConnect.mockClear();
221+
const pubsub = new PubSub();
222+
223+
const mqttOverWSProvider = new MqttOverWSProvider({
224+
aws_pubsub_region: 'region',
225+
aws_appsync_dangerously_connect_to_http_endpoint_for_testing: true
226+
});
227+
pubsub.addPluggable(mqttOverWSProvider);
228+
229+
await testPubSubAsync(pubsub, 'topicA', 'my message MqttOverWSProvider', {
230+
provider: 'MqttOverWSProvider',
231+
});
232+
233+
expect(mqttOverWSProvider.isSSLEnabled).toBe(false);
234+
expect(mockConnect).toBeCalledWith({
235+
useSSL: false,
236+
mqttVersion: 3,
237+
onSuccess: expect.any(Function),
238+
onFailure: expect.any(Function)
239+
});
240+
241+
});
242+
});
243+
216244
describe('multiple providers', () => {
217245
test('subscribe and publish to specific provider', async () => {
218246
const pubsub = new PubSub();

packages/pubsub/src/Providers/MqttOverWSProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
7878

7979
protected get clientsQueue() { return this._clientsQueue; }
8080

81+
protected get isSSLEnabled() {
82+
return !this.options.aws_appsync_dangerously_connect_to_http_endpoint_for_testing;
83+
}
84+
8185
protected getTopicForValue(value) { return typeof value === 'object' && value[topicSymbol]; }
8286

8387
getProviderName() { return 'MqttOverWSProvider'; }
@@ -99,10 +103,10 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
99103
client.onConnectionLost = ({ errorCode, ...args }) => {
100104
this.onDisconnect({ clientId, errorCode, ...args });
101105
};
102-
106+
103107
await new Promise((resolve, reject) => {
104108
client.connect({
105-
useSSL: true,
109+
useSSL: this.isSSLEnabled,
106110
mqttVersion: 3,
107111
onSuccess: () => resolve(client),
108112
onFailure: reject,

packages/pubsub/src/PubSub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class PubSub {
3636
*/
3737
private get awsAppSyncProvider() {
3838
if (!this._awsAppSyncProvider) {
39-
this._awsAppSyncProvider = new AWSAppSyncProvider();
39+
this._awsAppSyncProvider = new AWSAppSyncProvider(this._options);
4040
}
4141
return this._awsAppSyncProvider;
4242
}

packages/storage/__tests__/Providers/AWSS3Provider-unit-test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as S3 from 'aws-sdk/clients/s3';
1919
* actually be using dispatchStorageEvent from Storage
2020
*/
2121

22-
2322
S3.prototype.getSignedUrl = jest.fn((key, params) => {
2423
return 'url';
2524
});
@@ -87,7 +86,7 @@ describe('StorageProvider test', () => {
8786
});
8887

8988
describe('configure test', () => {
90-
test('happy case', () => {
89+
test('standard configuration', () => {
9190
const storage = new StorageProvider();
9291

9392
const aws_options = {
@@ -102,6 +101,26 @@ describe('StorageProvider test', () => {
102101
}
103102
});
104103
});
104+
105+
test('configuration for local testing', () => {
106+
const storage = new StorageProvider();
107+
108+
const aws_options = {
109+
aws_user_files_s3_bucket: 'bucket',
110+
aws_user_files_s3_bucket_region: 'region',
111+
aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing: true
112+
113+
}
114+
115+
const config = storage.configure(aws_options);
116+
expect(config).toEqual({
117+
AWSS3: {
118+
"bucket": "bucket",
119+
"region": "region",
120+
"dangerouslyConnectToHttpEndpointForTesting": true
121+
}
122+
});
123+
});
105124
});
106125

107126
describe('get test', async () => {

packages/storage/src/Providers/AWSS3Provider.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const dispatchStorageEvent = (track:boolean, event:string, attrs:any, metrics:an
3939
}
4040
};
4141

42+
const localTestingStorageEndpoint = 'http://localhost:20005';
43+
4244
/**
4345
* Provide storage methods to use AWS S3
4446
*/
@@ -403,14 +405,29 @@ export default class AWSS3Provider implements StorageProvider{
403405
* @private
404406
*/
405407
private _createS3(config) {
406-
const { bucket, region, credentials } = config;
408+
const {
409+
bucket,
410+
region,
411+
credentials,
412+
dangerouslyConnectToHttpEndpointForTesting
413+
} = config;
414+
let localTestingConfig = {};
415+
416+
if(dangerouslyConnectToHttpEndpointForTesting) {
417+
localTestingConfig = {
418+
endpoint: localTestingStorageEndpoint,
419+
s3BucketEndpoint: true,
420+
s3ForcePathStyle : true
421+
};
422+
}
407423

408424
return new S3({
409425
apiVersion: '2006-03-01',
410426
params: { Bucket: bucket },
411427
signatureVersion: 'v4',
412428
region,
413-
credentials
429+
credentials,
430+
...localTestingConfig
414431
});
415432
}
416433
}

0 commit comments

Comments
 (0)