Skip to content

Commit 7c95bd1

Browse files
committed
fix(rc): Add more unit tests for timestamp validation
1 parent 0d72380 commit 7c95bd1

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/remote-config/remote-config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ class VersionImpl implements Version {
362362
this.isLegacy = version.isLegacy;
363363
}
364364

365-
// The backend API provides timestamps as ISO date strings. The Admin SDK exposes timestamps
366-
// as UTC date strings. If a developer uses a previously obtained template with UTC timestamps
365+
// The backend API provides timestamps in ISO date strings. The Admin SDK exposes timestamps
366+
// in UTC date strings. If a developer uses a previously obtained template with UTC timestamps
367367
// we could still validate it below.
368368
if (typeof version.updateTime !== 'undefined') {
369369
if (!this.isValidTimestamp(version.updateTime)) {
@@ -392,6 +392,8 @@ class VersionImpl implements Version {
392392
}
393393

394394
private isValidTimestamp(timestamp: string): boolean {
395+
// This validation fails for timestamps earlier than January 1, 1970 and considers strings
396+
// such as "1.2" as valid timestamps.
395397
return validator.isNonEmptyString(timestamp) && (new Date(timestamp)).getTime() > 0;
396398
}
397399
}

test/unit/remote-config/remote-config.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ describe('RemoteConfig', () => {
681681
});
682682
});
683683

684-
it('should resolve with template when Version updateTime contains only 3 ms places', () => {
684+
it('should resolve with template when Version updateTime contains 3 fractional secs places', () => {
685685
const response = deepCopy(REMOTE_CONFIG_RESPONSE);
686686
const versionInfo = deepCopy(VERSION_INFO);
687687
versionInfo.updateTime = '2020-11-03T20:24:15.203Z';
@@ -707,7 +707,7 @@ describe('RemoteConfig', () => {
707707
});
708708
});
709709

710-
it('should resolve with template when Version updateTime contains 6 ms places', () => {
710+
it('should resolve with template when Version updateTime contains 6 fractional secs places', () => {
711711
const response = deepCopy(REMOTE_CONFIG_RESPONSE);
712712
const versionInfo = deepCopy(VERSION_INFO);
713713
versionInfo.updateTime = '2020-11-13T17:01:36.541527Z';
@@ -732,5 +732,31 @@ describe('RemoteConfig', () => {
732732
expect(version.updateTime).to.equal('Fri, 13 Nov 2020 17:01:36 GMT');
733733
});
734734
});
735+
736+
it('should resolve with template when Version updateTime contains 9 fractional secs places', () => {
737+
const response = deepCopy(REMOTE_CONFIG_RESPONSE);
738+
const versionInfo = deepCopy(VERSION_INFO);
739+
versionInfo.updateTime = '2020-11-13T17:01:36.541527341Z';
740+
response.version = versionInfo;
741+
const stub = sinon
742+
.stub(RemoteConfigApiClient.prototype, operationName)
743+
.resolves(response);
744+
stubs.push(stub);
745+
746+
return rcOperation()
747+
.then((template) => {
748+
expect(template.etag).to.equal('etag-123456789012-5');
749+
750+
const version = template.version!;
751+
expect(version.versionNumber).to.equal('86');
752+
expect(version.updateOrigin).to.equal('ADMIN_SDK_NODE');
753+
expect(version.updateType).to.equal('INCREMENTAL_UPDATE');
754+
expect(version.updateUser).to.deep.equal({
755+
756+
});
757+
expect(version.description).to.equal('production version');
758+
expect(version.updateTime).to.equal('Fri, 13 Nov 2020 17:01:36 GMT');
759+
});
760+
});
735761
}
736762
});

0 commit comments

Comments
 (0)