Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Fix Array Configurable CLI options #514

Merged
merged 5 commits into from
Jan 8, 2019
Merged

Conversation

shemnon
Copy link
Contributor

@shemnon shemnon commented Jan 6, 2019

PR description

The --host-whitelist and --rpc-cors-origins CLIs could not be configured as
a TOML array. The underlying PicoCLI issues were resolved with
revamped property types that act like Collections.

A "kitchen sink" test is added that creates a TOML file that
requires all CLI options to be configurable and configured in
a new kitchen_sink.toml test file.

--host-whitelist and --rpc-cors-origins could not be configured as
a TOML array.  The underlying PicoCLI issues were resolved with
revamped property types that act like Collections.

A "kitchen sink" test is added that creates a TOML file that
requires all CLI options to be configurable and configured in
a new kitchen_sink.toml test file.
shemnon and others added 2 commits January 7, 2019 09:32
use "everything_config" instead of the colloquial "kitchen sink"
and add more verbiage in the everything_config file.
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

Generally looks good just need to check the possible behaviour changes mentioned.

try {
final StringJoiner stringJoiner = new StringJoiner("|");
domains.forEach(stringJoiner::add);
Pattern.compile(stringJoiner.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like we're no longer filtering empty domains. Previously (I think) we threw an error if the overall list of domains was null or empty but if it was say domainA,,domainB we'd accept it and filter out the empty domain caused by the double commas. I'm assuming that PicoCLI won't ever try to add a null to this list but we may need to test that explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pico won't add nulls, but because of defense in depth I should check. I also now split on one or more commas, so a,,b will filter out the empty middle.

return new CorsAllowedOriginsProperty(Lists.newArrayList("*"));
} else if ("none".equals(s)) {
if (!domains.isEmpty()) {
throw new IllegalArgumentException("Value '" + s + "' can't be used with other domains");
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we'd now accept none,domainA,domainB whereas it would have previously been rejected because when none was added the list was empty even though it later became non-empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Checking on the individual case was inefficient, so I do a mass check in the addAll now.

throw new IllegalArgumentException("Domain cannot be empty string");
} else if ("all".equals(s) || "*".equals(s)) {
if (!domains.isEmpty()) {
throw new IllegalArgumentException("Value '" + s + "' can't be used with other domains");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as for none below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done the same as for none.

}
}
return true;
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 has the same potential behaviour changes as CorsAllowedOriginsProperty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I provided the same treatment for whitelist (except for the "this is a valid regex" check) now as cors-allowed-origins

@@ -881,8 +922,7 @@ public void jsonRpcCorsOriginsNoneWithAnotherDomainMustFail() {

@Test
public void jsonRpcCorsOriginsAllWithAnotherDomainMustFail() {
final String[] origins = {"http://domain1.com", "all"};
parseCommand("--rpc-cors-origins", String.join(",", origins));
parseCommand("--rpc-cors-origins=http://domain1.com,all");
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 a variants of this test with --rpc-cors-origins=all,http://domain1.com and --rpc-cors-origins= would be really useful and cover all the concerns I had above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added for whitelist and cores. Whitelist also gained some tests that it didn't have before to act like cors as well.

shemnon and others added 2 commits January 7, 2019 19:04
* move validation into "addAll"
* allow multiple commas
* more tests
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

LGTM.

@shemnon shemnon merged commit 8d4048b into PegaSysEng:master Jan 8, 2019
@shemnon shemnon deleted the CLI branch January 8, 2019 20:44
Errorific pushed a commit to Errorific/pantheon that referenced this pull request Jan 8, 2019
* Fix Array Configurable CLI options

--host-whitelist and --rpc-cors-origins could not be configured as
a TOML array.  The underlying PicoCLI issues were resolved with
revamped property types that act like Collections.

A "configure everything" test is added that creates a TOML file that
requires all CLI options to be configurable and configured in
a new everything_config.toml test file.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants