Skip to content

Check for null resourceName before attempted to delete a cert #669

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

Merged
merged 3 commits into from
Oct 16, 2019

Conversation

rsgowman
Copy link
Member

@rsgowman rsgowman commented Oct 9, 2019

Without this, the sdk will send a null resourceName to the server,
resulting in a somewhat misleading 404 error being returned.

Without this, the sdk will send a null resourceName to the server,
resulting in a somewhat misleading 404 error being returned.
@rsgowman rsgowman self-assigned this Oct 9, 2019
Copy link
Member Author

@rsgowman rsgowman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was motivated by me attempting to enable strict null checks throughout this repo.

@@ -175,6 +175,14 @@ describe('admin.projectManagement', () => {
expect(certs.length).to.equal(0);
});
});

it('add a cert and then remove it fails', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing the actual behaviour (both pre and post this PR) rather than the intended behaviour. It seems unfortunate that you can't delete a cert you just added (without going through getCerts first).

An alternative would be for the addShaCertificate to return a Promise where X is either the resourceName or the cert itself, populated with the resourceName (rather than void.) But that requires a minor API change.

Another alternative would be to mutate the cert passed to addShaCertificate to populate the resourceName. But that's a bit awkward since (a) mutating parameters is always a little awkward, and (b) it may need to be done asynchronously, so there'd be a timing consideration there too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CreateShaCertificate public API does return a ShaCertificate, so it's totally reasonable to update addShaCertificate to return Promise<ShaCertificate>. I would not recommend mutating the ShaCertificate that was passed to addShaCertificate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a Promise sounds like a good idea. And not a breaking change in this case.

@rsgowman rsgowman requested review from nbegley and hiranya911 October 9, 2019 16:19
@rsgowman rsgowman assigned hiranya911 and nbegley and unassigned rsgowman Oct 9, 2019
Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Lets wait for @nbegley to also have a look.

@@ -175,6 +175,14 @@ describe('admin.projectManagement', () => {
expect(certs.length).to.equal(0);
});
});

it('add a cert and then remove it fails', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a Promise sounds like a good idea. And not a breaking change in this case.

@hiranya911 hiranya911 removed their assignment Oct 9, 2019
@@ -175,6 +175,14 @@ describe('admin.projectManagement', () => {
expect(certs.length).to.equal(0);
});
});

it('add a cert and then remove it fails', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CreateShaCertificate public API does return a ShaCertificate, so it's totally reasonable to update addShaCertificate to return Promise<ShaCertificate>. I would not recommend mutating the ShaCertificate that was passed to addShaCertificate.

admin.projectManagement().shaCertificate(SHA_256_HASH);
return androidApp.addShaCertificate(shaCertificate)
.then(() => androidApp.deleteShaCertificate(shaCertificate))
.should.eventually.be.rejected;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to check that the rejection reason is the new FirebaseError you added, and make the it(...) description of this test indicate why it should fail (ie. no resourceName).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strangely, I couldn't get .should.eventually.be.rejectedWith(FirebaseProjectManagementError) to work, so instead I did .rejectedWith('error message here'). The other integration tests seem to do the same.

@nbegley nbegley assigned rsgowman and unassigned nbegley Oct 9, 2019
@rsgowman rsgowman assigned nbegley and unassigned rsgowman Oct 15, 2019
@rsgowman rsgowman merged commit 406e5c8 into master Oct 16, 2019
@rsgowman rsgowman deleted the rsgowman/deleteShaCertNullCheck branch October 16, 2019 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants