Skip to content

Commit 22ecc0b

Browse files
nMonchoGustavo De Michelijeremylong
authored
fix: Disable OSS Index if its credentials are missing (#7963)
Co-authored-by: Gustavo De Micheli <[email protected]> Co-authored-by: Jeremy Long <[email protected]>
1 parent 93422d2 commit 22ecc0b

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

core/src/main/java/org/owasp/dependencycheck/analyzer/OssIndexAnalyzer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ protected void prepareAnalyzer(Engine engine) throws InitializationException {
134134
synchronized (FETCH_MUTIX) {
135135
if (StringUtils.isEmpty(getSettings().getString(KEYS.ANALYZER_OSSINDEX_USER, StringUtils.EMPTY)) ||
136136
StringUtils.isEmpty(getSettings().getString(KEYS.ANALYZER_OSSINDEX_PASSWORD, StringUtils.EMPTY))) {
137-
throw new InitializationException("Error initializing OSS Index analyzer due to missing user/password credentials. Authentication is now required: https://ossindex.sonatype.org/doc/auth-required");
137+
LOG.warn("Disabling OSS Index analyzer due to missing user/password credentials. Authentication is now required: https://ossindex.sonatype.org/doc/auth-required");
138+
setEnabled(false);
138139
}
139140
}
140141
}

core/src/test/java/org/owasp/dependencycheck/analyzer/OssIndexAnalyzerTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.owasp.dependencycheck.dependency.Dependency;
99
import org.owasp.dependencycheck.dependency.naming.Identifier;
1010
import org.owasp.dependencycheck.dependency.naming.PurlIdentifier;
11-
import org.owasp.dependencycheck.exception.InitializationException;
1211
import org.owasp.dependencycheck.utils.Settings;
1312
import org.owasp.dependencycheck.utils.Settings.KEYS;
1413

@@ -30,7 +29,7 @@
3029

3130
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3231
import static org.junit.jupiter.api.Assertions.assertEquals;
33-
import static org.junit.jupiter.api.Assertions.assertThrows;
32+
import static org.junit.jupiter.api.Assertions.assertFalse;
3433
import static org.junit.jupiter.api.Assertions.assertTrue;
3534

3635
class OssIndexAnalyzerTest extends BaseTest {
@@ -252,18 +251,21 @@ void should_analyzeDependency_fail_when_socket_error_from_sonatype() throws Exce
252251
}
253252

254253
@Test
255-
void should_prepareAnalyzer_fail_when_credentials_not_set() throws Exception {
254+
void should_prepareAnalyzer_disable_when_credentials_not_set() throws Exception {
255+
// Given
256256
OssIndexAnalyzer analyzer = new OssIndexAnalyzer();
257257
Settings settings = getSettings();
258258
Engine engine = new Engine(settings);
259259
analyzer.initialize(settings);
260-
try {
261-
analyzer.prepareAnalyzer(engine);
262-
assertThrows(InitializationException.class, () -> analyzer.prepareAnalyzer(engine));
263-
} catch (InitializationException e) {
264-
analyzer.close();
265-
engine.close();
266-
}
260+
261+
// When
262+
analyzer.prepareAnalyzer(engine);
263+
264+
// Then
265+
boolean enabled = analyzer.isEnabled();
266+
analyzer.close();
267+
engine.close();
268+
assertFalse(enabled);
267269
}
268270

269271
private static void setCredentials(final Settings settings) {

src/site/markdown/analyzers/oss-index-analyzer.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ Sonatype [announced](https://ossindex.sonatype.org/doc/auth-required) that OSS I
1313

1414
You can get an API Token following these steps:
1515
1. [Sign In](https://ossindex.sonatype.org/user/signin) or [Sign Up](https://ossindex.sonatype.org/user/register) for free.
16-
2. Get the API Token from user Settings.
16+
2. Get the API Token from user Settings.
17+
18+
If no credentials are provided, this analyzer will be disabled.

0 commit comments

Comments
 (0)