-
Notifications
You must be signed in to change notification settings - Fork 242
Add a reserved namespaces deny list to restrict trait-codegen from using smithy specific namespaces. #2709
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
Add a reserved namespaces deny list to restrict trait-codegen from using smithy specific namespaces. #2709
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...t-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenSettingsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.traitcodegen; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.stream.Stream; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| class TraitCodegenSettingsTest { | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { | ||
| "smithy", | ||
| "smithy.api", | ||
| "smithy.waiters", | ||
| "smithy.test", | ||
| "smithy.api.foo", | ||
| "smithy.waiters.bar", | ||
| "smithy.test.baz", | ||
| "Smithy.api", | ||
| "sMithy", | ||
| "smithy.API", | ||
| "smiThy.Api.Baz" | ||
| }) | ||
| void constructorRejectsReservedNamespaces(String namespace) { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, | ||
| () -> new TraitCodegenSettings("com.example", | ||
| namespace, | ||
| Collections.emptyList(), | ||
| Collections.emptyList())); | ||
| assertEquals("The `smithy` namespace and its sub-namespaces are reserved.", exception.getMessage()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { | ||
| "smithy.foo", | ||
| "smithy.bar.baz", | ||
| "example.namespace", | ||
| "my.custom.namespace", | ||
| "smithy.custom", | ||
| "smithyapi", | ||
| "smithy.apiextension" | ||
| }) | ||
| void constructorAcceptsValidNamespaces(String namespace) { | ||
| assertDoesNotThrow(() -> new TraitCodegenSettings( | ||
| "com.example", | ||
| namespace, | ||
| Collections.emptyList(), | ||
| Collections.emptyList())); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("nullParameterCombinations") | ||
| void constructorRequiresNonNullParameters(String packageName, String namespace) { | ||
| assertThrows(NullPointerException.class, | ||
| () -> new TraitCodegenSettings(packageName, | ||
| namespace, | ||
| Collections.emptyList(), | ||
| Collections.emptyList())); | ||
| } | ||
|
|
||
| static Stream<Arguments> nullParameterCombinations() { | ||
| return Stream.of( | ||
| Arguments.of(null, "smithy.foo"), | ||
| Arguments.of("com.example", null)); | ||
| } | ||
|
|
||
| @Test | ||
| void gettersReturnCorrectValues() { | ||
| TraitCodegenSettings settings = new TraitCodegenSettings( | ||
| "com.example", | ||
| "smithy.foo", | ||
| Collections.emptyList(), | ||
| Collections.emptyList()); | ||
|
|
||
| assertEquals("com.example", settings.packageName()); | ||
| assertEquals("smithy.foo", settings.smithyNamespace()); | ||
| assertEquals(Collections.emptyList(), settings.headerLines()); | ||
| assertEquals(Collections.emptyList(), settings.excludeTags()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this conversion, namespaces are case sensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed offline that this needs to be case sensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, while namespaces are case-sensitive, the rationale of this was anyone should be forbidden from creating a trait with
SMITHYorSMITHY.APIor other versions of it as it conflicts with our reserved namespaces.I am leaning towards blocking those case-insensitively. @mtdowling and I discussed, the reasoning for case-insensitive checking is that shapes are case-insensitive.
FWIW, for future record putting this here from our docs :