Skip to content

Fix Azure Batch netcore header signing#3206

Merged
shahabhijeet merged 4 commits intoAzure:vs17Devfrom
matthchr:bugfix/fix-netcore-headersigning
May 15, 2017
Merged

Fix Azure Batch netcore header signing#3206
shahabhijeet merged 4 commits intoAzure:vs17Devfrom
matthchr:bugfix/fix-netcore-headersigning

Conversation

@matthchr
Copy link
Copy Markdown
Member

Description


This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code.
  • The *.csproj and AssemblyInfo.cs files have been updated with the new version of the SDK.

@matthchr
Copy link
Copy Markdown
Member Author

This fixes issue #3170

@matthchr
Copy link
Copy Markdown
Member Author

Please DO NOT MERGE until I get signoff from my team members: @itowlson @darylmsft @xingwu1 @kiwidev

I will respond once we are ready to merge.

@shahabhijeet
Copy link
Copy Markdown
Contributor

@matthchr please remove "Do not merge" label and add need-review, so that I know it is ready to be reviewed.

@matthchr
Copy link
Copy Markdown
Member Author

@shahabhijeet Thanks, didn't realize we had those labels. In the future I can add them myself as well.

I'll let you know when we're ready to merge.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

are these methods usually named async Task XxxYyyAsync()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Normal convention is not to add Async suffix to tests - they are leaf methods and never called by other places. I'm unsure if there is other prior art in this project though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 - the Async suffix is a hint to human callers of a method, which is not an issue for tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The tests in these projects don't mention Async (even if they are async). Leaving this as is.

Copy link
Copy Markdown
Member

@kiwidev kiwidev left a comment

Choose a reason for hiding this comment

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

I think the logic is ok, comments are related to the tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to iterate through ports until we find a free one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While these tests are good, they test an aspect of the underlying behavior, but don't seem to actually test our shared key algorithm. What we're wanting to do is enforce that the StringToSign that we computed (made up of headers etc) matches the StringToSign that would be computed by the server (based on the headers sent).
So we'd either need a way of extracting the StringToSign from our BatchSharedKeyCredential (do we expose this?) or else compute the hash again on the server side and validate that they match.

I think we should keep these tests too as a way of exploring the underlying functionality / confirming that different platforms don't change behavior, however the "SharedKeyAuth" doesn't seem to belong inside this test as it isn't being asserted against.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agree with basically all you said.

So we'd either need a way of extracting the StringToSign from our BatchSharedKeyCredential (do we expose this?) or else compute the hash again on the server side and validate that they match.

Yes, I have another item to enable the end to end integration tests to run in both netcore and netframework, but in order to do that there is more work required. So instead of doing that for this issue (since it's customer impacting), I added a targeted unit test. We will circle back around and enable the end to end tests to run against both, at which point we should get the validation we seek (since the E2E tests use all the different verbs)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll fix the name of the test class/test to more clearly describe what it is testing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Patch?
Options?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Daryl brought this up too... even though we don't use Options anywhere internally, I guess I'll add it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd still prefer that the #if FullNetFx was outside of the if statement so we're not generating an empty if for dotNetCore.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Alright - I've made that change

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Assert that it's equal to 0?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test name does not describe what is being asserted/tested. Reading the code this one seems to contain a number of assertions, not all of which relate to content length; and the content length assertions vary from HTTP method to HTTP method. So I'm not sure what to suggest as a better name except that it should be a statement which can be true or false. (You might want to consider breaking out the different HTTP methods so you could have more specific test names for each, e.g. HttpDelete_WithSharedKeySigning_DoesNotIncludeContentLength.)

Copy link
Copy Markdown
Member Author

@matthchr matthchr May 15, 2017

Choose a reason for hiding this comment

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

The issue with a line in the sand name like "DoesNot" or "Does" with respect to including content length is that the behavior varies across target framework, so unless I conditionally compile the whole test out, it's going to be wrong for one of the frameworks when it comes to DELETE

I could add a bunch of tests clearly spelling out each case (either does or does not), but they would all just call into a common helper function, which is why I just used Theory instead.

I've changed this to be: HttpClient_IncludesContentLengthHeaderOnExpectedHttpVerbs. Obviously what is "Expected" is still nebulous (you have to read the test code)...

Let me know if you don't think this is sufficient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function name doesn't mean a whole lot to me. 'Lambda' seems to describe more its intended usage than its actual semantics...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed I think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Putting this long local function in the middle of test impacts readability. Consider restructuring to keep the test readable top-to-bottom.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is HttpMethod an enum? If so consider using a switch instead of a series of if-clauses.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sadly it's not an enum

matthchr added 4 commits May 15, 2017 11:03
  - This is due to a change in HttpClient where DELETE no longer
    always includes a Content-Length 0 header. This is a change from
    net452 where DELETE always has that header.
  - Also includes a test for this behavior.
@matthchr matthchr force-pushed the bugfix/fix-netcore-headersigning branch from 454ac79 to dcdb02c Compare May 15, 2017 18:19
@matthchr
Copy link
Copy Markdown
Member Author

@shahabhijeet - Okay, this needs review from an SDK team member and merge now.

@shahabhijeet shahabhijeet merged commit ea982f3 into Azure:vs17Dev May 15, 2017
@matthchr matthchr deleted the bugfix/fix-netcore-headersigning branch May 15, 2017 20:20
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.

6 participants