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

udpa: UDPA URL encoding/decoding utils. #11805

Merged
merged 6 commits into from
Jul 1, 2020

Conversation

htuch
Copy link
Member

@htuch htuch commented Jun 29, 2020

This patch introduces support for encoding/decoding
udpa::core::v1::ResourceLocator, in addition to the existing support for
udpa::core::v1::ResourceName. Some refactoring and attention to the
URI/URN/URL distinction (as per RFC3986) is introduced.

Part of #11264

Risk level: Low (not used)
Testing: Additional unit tests for URLs added.

Signed-off-by: Harvey Tuch [email protected]

This patch introduces support for encoding/decoding
udpa::core::v1::ResourceLocator, in addition to the existing support for
udpa::core::v1::ResourceName. Some refactoring and attention to the
URI/URN/URL distinction (as per RFC3986) is introduced.

Risk level: Low (not used)
Testing: Additional unit tests for URLs added.

Signed-off-by: Harvey Tuch <[email protected]>
htuch added 2 commits June 29, 2020 16:38
markdroth
markdroth previously approved these changes Jun 30, 2020
Copy link
Contributor

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This looks good! Just a couple of minor comments.

source/common/config/udpa_resource.cc Outdated Show resolved Hide resolved
UdpaResourceIdentifier::decodeUrl(EscapedUrlWithManyQueryParamsAndDirectives);
EXPECT_EQ("f123%/?#o", resource_locator.authority());
EXPECT_EQ("envoy.config.listener.v3.Listener", resource_locator.resource_type());
EXPECT_EQ(3, resource_locator.id().size());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better written as follows, both for readability and for more useful output when the test fails:

EXPECT_THAT(resource_locator.id(), ::testing::ElementsAre("b%:/?#[]ar", "", "baz"));

Same thing for all repeated fields throughout this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, but not for directives, since when working with proto types you don't get for free equality and nice debug string output. It's possible to do this with some extra work, but not worth it in this case IMHO.

test/common/config/udpa_resource_test.cc Outdated Show resolved Hide resolved
mattklein123
mattklein123 previously approved these changes Jun 30, 2020
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM other than Mark comments. Ultimately it would probably be worth it to write a small fuzzer for the encoding/decoding stuff.

Signed-off-by: Harvey Tuch <[email protected]>
@htuch htuch dismissed stale reviews from mattklein123 and markdroth via 880c4d4 June 30, 2020 18:08
markdroth
markdroth previously approved these changes Jun 30, 2020
Copy link
Contributor

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

Looks great!


#define EXPECT_CONTEXT_PARAMS(context_params, ...) \
{ \
std::map<std::string, std::string> param_map((context_params).begin(), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it necessary to convert to std::map<> here? Doesn't the protobuf map field accessor provide the same interface as std::map<>, such that it works directly with UnorderedElementsAre()?

I would think that you could just say EXPECT_THAT(resource_name.context().params(), UnorderedElementsAre(...)).

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't work, since what you get is a comparison on the proto MapPair object, which does not pretty-print on failure, i.e. you see stuff like:

Expected: has 2 elements and there exists some permutation of elements such that:
 - element #0 has a first field that is equal to "%#[]&=", and has a second field that is equal to "bar", and
 - element #1 has a first field that is equal to "foo", and has a second field that is equal to "%#[]&="
  Actual: { 48-byte object <06-66 6F-6F 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 0C-25 23-5B 5D-26 3D-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00>, 48-byte object <10-25 23-5B 5D-26 3D-61 62-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 14-63 64-65 25-23 5B-5D 26-3D 66-00 00-00 00-00 00-00 00-00 00-00 00-00>, 48-byte object <0C-25 23-5B 5D-26 3D-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 06-62 61-72 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00> }, which has 3 elements

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, okay. That's too bad.

Might be worth adding a comment about why this conversion is necessary.

test/common/config/udpa_resource_test.cc Outdated Show resolved Hide resolved
test/common/config/udpa_resource_test.cc Show resolved Hide resolved
test/common/config/udpa_resource_test.cc Outdated Show resolved Hide resolved

#define EXPECT_CONTEXT_PARAMS(context_params, ...) \
{ \
std::map<std::string, std::string> param_map((context_params).begin(), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, okay. That's too bad.

Might be worth adding a comment about why this conversion is necessary.

Signed-off-by: Harvey Tuch <[email protected]>
@htuch htuch merged commit 76525d8 into envoyproxy:master Jul 1, 2020
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