Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;

public class DetectionWithSubRuleTestFile {

void test(Cipher cipher) throws InvalidKeyException {
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec("0123456789ABCDEF".getBytes(), "AES")); // Noncompliant {{2}}
void test() throws Exception {
Cipher cipher = Cipher.getInstance("AES"); // Noncompliant {{AES}}
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec("0123456789ABCDEF".getBytes(), "AES")); // Noncompliant {{128}} {{2}} {{AES}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@

import com.ibm.engine.detection.DetectionStore;
import com.ibm.engine.detection.Finding;
import com.ibm.engine.utils.DetectionStoreLogger;
import com.ibm.mapper.model.INode;
import com.ibm.plugin.TestBase;
import com.ibm.plugin.rules.detection.jca.cipher.JcaCipherGetInstance;
import java.util.List;
import javax.annotation.Nonnull;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.sonar.check.Rule;
import org.sonar.java.checks.verifier.CheckVerifier;
Expand All @@ -51,7 +49,6 @@ public void asserts(
// nothing
}

@Disabled("")
@Test
void test() {
CheckVerifier.newVerifier()
Expand All @@ -62,15 +59,18 @@ void test() {

@Override
public void update(@Nonnull Finding<JavaCheck, Tree, Symbol, JavaFileScannerContext> finding) {
final DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext> detectionStore =
finding.detectionStore();
(new DetectionStoreLogger<JavaCheck, Tree, Symbol, JavaFileScannerContext>())
.print(detectionStore);
detectionStore
.getDetectionValues()
.forEach(
iValue -> {
this.reportIssue(iValue.getLocation(), iValue.asString());
});
reportStore(finding.detectionStore());
}

private void reportStore(
DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext> store) {
if (store == null) {
return;
}

store.getDetectionValues()
.forEach(value -> this.reportIssue(value.getLocation(), value.asString()));

store.getChildren().forEach(this::reportStore);
}
}