Repository navigation
ACOMMONS-237 Export the S5332 identifier URL inventory through the shared npm package #590
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
Closed
Closed
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
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
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
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
52 changes: 52 additions & 0 deletions
52
.../src/main/java/org/sonarsource/analyzer/commons/appsec/export/IdentifierUrlsExporter.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,52 @@ | ||
| /* | ||
| * SonarSource Analyzers Commons Configurations | ||
| * Copyright (C) SonarSource Sàrl | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * You can redistribute and/or modify this program under the terms of | ||
| * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the Sonar Source-Available License for more details. | ||
| * | ||
| * You should have received a copy of the Sonar Source-Available License | ||
| * along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
| */ | ||
| package org.sonarsource.analyzer.commons.appsec.export; | ||
|
|
||
| import com.google.gson.JsonObject; | ||
| import java.util.TreeMap; | ||
| import org.sonarsource.analyzer.commons.appsec.CleartextProtocolFilter; | ||
|
|
||
| /** | ||
| * Generates the identifier URL inventory shared with non-JVM analyzers. | ||
| */ | ||
| public final class IdentifierUrlsExporter { | ||
|
|
||
| private IdentifierUrlsExporter() { | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| if (args.length < 1) { | ||
| throw new IllegalArgumentException("Usage: IdentifierUrlsExporter <output-json-path>"); | ||
| } | ||
| JsonExports.write(args[0], toJson()); | ||
| } | ||
|
|
||
| /** | ||
| * Converts the Java identifier inventory to JSON text, with entries sorted by domain. | ||
| * Example output for an empty inventory: | ||
| * <pre>{@code | ||
| * { | ||
| * } | ||
| * }</pre> | ||
| * The caller writes the returned text to {@code identifier-urls.json}. | ||
| */ | ||
| public static String toJson() { | ||
| JsonObject root = new JsonObject(); | ||
| new TreeMap<>(CleartextProtocolFilter.exportIdentifierUrls()).forEach(root::addProperty); | ||
| return JsonExports.render(root); | ||
| } | ||
| } |
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
5 changes: 3 additions & 2 deletions
5
sonar-analyzer-commons-configurations/src/main/packaging/npm/package.json
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
56 changes: 56 additions & 0 deletions
56
.../test/java/org/sonarsource/analyzer/commons/appsec/export/IdentifierUrlsExporterTest.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,56 @@ | ||
| /* | ||
| * SonarSource Analyzers Commons Configurations | ||
| * Copyright (C) SonarSource Sàrl | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * You can redistribute and/or modify this program under the terms of | ||
| * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the Sonar Source-Available License for more details. | ||
| * | ||
| * You should have received a copy of the Sonar Source-Available License | ||
| * along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
| */ | ||
| package org.sonarsource.analyzer.commons.appsec.export; | ||
|
|
||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonParser; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
| import org.sonarsource.analyzer.commons.appsec.CleartextProtocolFilter; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| class IdentifierUrlsExporterTest { | ||
|
|
||
| @Test | ||
| void jsonShouldMatchTheEmptyInventory() { | ||
| JsonObject inventory = JsonParser.parseString(IdentifierUrlsExporter.toJson()).getAsJsonObject(); | ||
|
|
||
| assertThat(inventory.keySet()).isEmpty(); | ||
| assertThat(CleartextProtocolFilter.exportIdentifierUrls()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void mainShouldWriteJsonToTheGivenPath(@TempDir Path tempDir) throws IOException { | ||
| Path output = tempDir.resolve("generated-resources").resolve("identifier-urls.json"); | ||
|
|
||
| IdentifierUrlsExporter.main(new String[] {output.toString()}); | ||
|
|
||
| assertThat(Files.readString(output)).isEqualTo(IdentifierUrlsExporter.toJson()); | ||
| } | ||
|
|
||
| @Test | ||
| void mainShouldFailWhenNoOutputPathIsGiven() { | ||
| assertThatThrownBy(() -> IdentifierUrlsExporter.main(new String[0])) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessageContaining("Usage"); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
💡 Quality: Identifier matching semantics are now dead code with no tests
With
IDENTIFIER_URLS = Map.of(), the lookup at line 246 always returns null, so the suffix normalisation and case-sensitivefind()at lines 247-252 never run. This delta also deleted the tests that covered them: exact authority with port, the empty-suffix/, the/prefix for?/#, and case-sensitive paths. The only test left checks one negative lookup. The javadoc (lines 238-239) and the npm README (lines 29-39) still promise these semantics to non-JVM consumers, but nothing checks them. A regression would only show up once the inventory is filled in, and it would spread to SonarJS through the exported JSON. To fix this, add a package-private overloadisKnownIdentifier(String url, Map<String, Pattern> inventory)that the public method calls, and bring back the semantic tests against a test-only map such asexample.invalid -> ^/schema.Make the matcher testable independently of the (currently empty) production inventory.:
Was this helpful? React with 👍 / 👎