Skip to content
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

Initial structure for cpg native queries and and a small example #865

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions codyze-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
implementation(projects.codyzeCore)
implementation(projects.codyzeBackends.cpg)
implementation(projects.codyzeSpecificationLanguages.coko.cokoDsl)
implementation(projects.codyzeSpecificationLanguages.cpgNative)

implementation(libs.clikt)
implementation(libs.koin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import de.fraunhofer.aisec.codyze.core.executor.ExecutorCommand
import de.fraunhofer.aisec.codyze.core.output.OutputBuilder
import de.fraunhofer.aisec.codyze.core.output.SarifBuilder
import de.fraunhofer.aisec.codyze.core.plugin.Plugin
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.CPGQuerySubcommand
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.dsl.cli.CokoSubcommand
import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.bind
Expand All @@ -42,6 +43,7 @@ val backendCommands = module {
* Each [Executor] must provide a [ExecutorCommand] to be selectable in the CLI.
*/
val executorCommands = module {
factoryOf(::CPGQuerySubcommand) bind(ExecutorCommand::class)
factoryOf(::CokoSubcommand) bind(ExecutorCommand::class)
}

Expand Down
38 changes: 38 additions & 0 deletions codyze-specification-languages/cpg-native/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id("documented-module")
id("publish")
}

dependencies {
implementation(projects.codyzeCore)
implementation(projects.codyzeSpecificationLanguages.coko.cokoCore)
implementation(projects.codyzeBackends.cpg) // used only for the CokoScript plugin block configuration
implementation(libs.bundles.cpg)
implementation(libs.kotlin.reflect)

implementation(libs.sarif4k)
implementation(libs.koin)
implementation(libs.clikt)

// For testing with koin
// kotlin-test-junit has to be excluded because it is loaded by "documented-module" plugin
testImplementation(libs.koin.test) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-test-junit")
}
testImplementation(libs.koin.junit5) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-test-junit")
}
testImplementation(libs.mockk)
testImplementation(libs.bundles.cpg)
}

publishing {
publications {
named<MavenPublication>(name) {
pom {
name.set("Codyze Specification Language Native CPG Query DSL")
description.set("Queries with native CPG DSL for Codyze")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt.

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

import de.fraunhofer.aisec.codyze.core.executor.ExecutorConfiguration
import io.github.oshai.kotlinlogging.KotlinLogging

private val logger = KotlinLogging.logger { }

Check warning on line 6 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt#L6

Added line #L6 was not covered by tests

data class CPGQueryConfiguration(
val runQueries: Boolean // Queries may be turned of, if all executors are run and queries shoul be excluded

Check warning on line 9 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt#L8-L9

Added lines #L8 - L9 were not covered by tests
) : ExecutorConfiguration {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

The class or object CPGQueryConfiguration is empty.

Check warning

Code scanning / detekt

Reports empty class bodies Warning

Unnecessary block ("{}")

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt is not ending with a new line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt.

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

import de.fraunhofer.aisec.codyze.core.executor.Executor

Check warning

Code scanning / detekt

Detects imports in non default order Warning

Imports must be ordered in lexicographic order without any empty lines in-between with "java", "javax", "kotlin" and aliases in the end
import de.fraunhofer.aisec.codyze.backends.cpg.CPGBackend
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.CPGQuery
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.ExampleQuery
import io.github.detekt.sarif4k.Run
import io.github.oshai.kotlinlogging.KotlinLogging


private val logger = KotlinLogging.logger {}

Check warning

Code scanning / detekt

Reports consecutive blank lines Warning

Needless blank line(s)

Check warning on line 11 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L11

Added line #L11 was not covered by tests

/**
* The [Executor] to run natively defined CPG queries on the cpg backend, generating Sarif output
*/

class CPGQueryExecutor(private val configuration: CPGQueryConfiguration, private val backend: CPGBackend) :

Check warning

Code scanning / detekt

Property is unused and should be removed. Warning

Private property configuration is unused.

Check warning on line 17 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L17

Added line #L17 was not covered by tests
Executor {
private val queries: MutableList<CPGQuery> = mutableListOf()

Check warning on line 19 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L19

Added line #L19 was not covered by tests

init {
queries.add(ExampleQuery())

Check warning on line 22 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L21-L22

Added lines #L21 - L22 were not covered by tests
}

override fun evaluate(): Run {
logger.info { "Running CPG Queries" }
val findings: MutableMap<CPGQuery,List<CpgQueryFinding>> = mutableMapOf()

Check warning

Code scanning / detekt

Reports spaces around commas Warning

Missing spacing after ","

Check warning on line 27 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L26-L27

Added lines #L26 - L27 were not covered by tests

queries.forEach {
findings.put(it, it.query(backend))

Check warning on line 30 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L29-L30

Added lines #L29 - L30 were not covered by tests
}

val cpgQuerySarifBuilder = CPGQuerySarifBuilder(queries = queries, backend = backend)
return cpgQuerySarifBuilder.buildRun(findings = findings)

Check warning on line 34 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L33-L34

Added lines #L33 - L34 were not covered by tests
}
}

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt is not ending with a new line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt.

Check warning

Code scanning / detekt

Checks if top level class matches the filename Warning

File 'CPGQueryFinding.kt' contains a single class and possibly also extension functions for that class and should be named same after that class 'CpgQueryFinding.kt'

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

import de.fraunhofer.aisec.codyze.backends.cpg.coko.getSarifLocation
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.CPGQuery
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.Finding
import de.fraunhofer.aisec.cpg.graph.Node
import io.github.detekt.sarif4k.Artifact
import io.github.detekt.sarif4k.Level
import io.github.detekt.sarif4k.Message
import io.github.detekt.sarif4k.Result
import java.nio.file.Path

/**
* An implementation of a [Finding] specifically for native queries.
*/
data class CpgQueryFinding(

Check warning

Code scanning / detekt

If a source file contains only a single non-private top-level class or object, the file name should reflect the case-sensitive name plus the .kt extension. Warning

The file name 'CPGQueryFinding' does not match the name of the single top-level declaration 'CpgQueryFinding'.
val message: String,
val kind: Finding.Kind = Finding.Kind.Fail,
val node: Node? = null,
val relatedNodes: Collection<Node>? = null,

Check warning on line 20 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L16-L20

Added lines #L16 - L20 were not covered by tests
) {
fun toSarif(query: CPGQuery, queries: List<CPGQuery>, artifacts: Map<Path, Artifact>?) =
Result(
message = Message(text = message),
kind = kind.resultKind,

Check warning on line 25 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L23-L25

Added lines #L23 - L25 were not covered by tests
level = if (kind == Finding.Kind.Fail) {
query.level

Check warning on line 27 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L27

Added line #L27 was not covered by tests
} else {
Level.None

Check warning on line 29 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L29

Added line #L29 was not covered by tests
},
ruleIndex = queries.indexOf(query).toLong(),

Check warning on line 31 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L31

Added line #L31 was not covered by tests
locations = node?.let { listOf(node.getSarifLocation(artifacts)) },
relatedLocations = relatedNodes?.map { node ->
node.getSarifLocation(artifacts)

Check warning on line 34 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L34

Added line #L34 was not covered by tests
}
)
}

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt is not ending with a new line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt.

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

import de.fraunhofer.aisec.codyze.core.executor.ExecutorOptions
import io.github.oshai.kotlinlogging.KotlinLogging

private val logger = KotlinLogging.logger {}

Check warning on line 6 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt#L6

Added line #L6 was not covered by tests

/**
* Contains all the options specific to the [CPGQueryExecutor]. For now this option group is an empty dummy.
*/
@Suppress("UNUSED")
class CPGQueryOptionGroup : ExecutorOptions("CPG Query Options") { }

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

The class or object CPGQueryOptionGroup is empty.

Check warning

Code scanning / detekt

Reports empty class bodies Warning

Unnecessary block ("{}")

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt is not ending with a new line.

Check warning on line 12 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt#L12

Added line #L12 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt.

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

import de.fraunhofer.aisec.codyze.core.VersionProvider
import de.fraunhofer.aisec.codyze.core.backend.Backend
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.CPGQuery
import io.github.detekt.sarif4k.*
import kotlin.reflect.full.findAnnotation

Check warning

Code scanning / detekt

Detects unused imports Warning

Unused import

private fun CPGQuery.toReportingDescriptor() = ReportingDescriptor(
id = id,
name = javaClass.simpleName,
shortDescription = MultiformatMessageString(text = shortDescription),

Check warning

Code scanning / detekt

Reports multiple space usages Warning

Unnecessary long whitespace
fullDescription = MultiformatMessageString(text = description),
defaultConfiguration = ReportingConfiguration(level = level),
help = MultiformatMessageString(text = help)

Check warning on line 15 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L9-L15

Added lines #L9 - L15 were not covered by tests
,

Check warning

Code scanning / detekt

Reports spaces around commas Warning

Unexpected spacing before ","
properties =
PropertyBag(

Check warning

Code scanning / detekt

Reports mis-indented code Warning

Unexpected indentation (8) (should be 4)
tags = tags.toSet(),

Check warning

Code scanning / detekt

Reports mis-indented code Warning

Unexpected indentation (12) (should be 8)
map = emptyMap()

Check warning

Code scanning / detekt

Reports mis-indented code Warning

Unexpected indentation (12) (should be 8)

Check warning on line 20 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L18-L20

Added lines #L18 - L20 were not covered by tests
)

Check warning

Code scanning / detekt

Reports mis-indented code Warning

Unexpected indentation (8) (should be 4)
,

Check warning

Code scanning / detekt

Reports spaces around commas Warning

Unexpected spacing before ","
)

class CPGQuerySarifBuilder(val queries: List<CPGQuery>, val backend: Backend) {
val reportingDescriptors = queries.map { it.toReportingDescriptor() }
val toolComponent = ToolComponent(
name = "CPGQueryExecutor",
product = "Codyze",
organization = "Fraunhofer AISEC",
semanticVersion = VersionProvider.getVersion("cpg-queries"),
downloadURI = "https://github.com/Fraunhofer-AISEC/codyze/releases",
informationURI = "https://www.codyze.io",
rules = reportingDescriptors,

Check warning on line 34 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L25-L34

Added lines #L25 - L34 were not covered by tests
)

fun buildRun(findings: Map<CPGQuery, List<CpgQueryFinding>>): Run {
// build the SARIF run based on the received results
return Run(
tool = Tool(
driver = toolComponent,
extensions = listOf(backend.toolInfo)

Check warning on line 42 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L39-L42

Added lines #L39 - L42 were not covered by tests
),
artifacts = backend.artifacts.values.toList(),
results = findings.entries.flatMap { entry ->
entry.value.map { it.toSarif(entry.key, queries, backend.artifacts) }

Check warning on line 46 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L44-L46

Added lines #L44 - L46 were not covered by tests
}
)
}
}

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt is not ending with a new line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt.

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

Check warning on line 1 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L1

Added line #L1 was not covered by tests

import com.github.ajalt.clikt.parameters.groups.provideDelegate
import de.fraunhofer.aisec.codyze.backends.cpg.CPGBackend
import de.fraunhofer.aisec.codyze.core.backend.Backend
import de.fraunhofer.aisec.codyze.core.executor.ExecutorCommand

@Suppress("UNUSED")
class CPGQuerySubcommand: ExecutorCommand<CPGQueryExecutor>("runNativeQueries") {

Check warning

Code scanning / detekt

Reports spaces around colons Warning

Missing spacing before ":"
val executorOptions by CPGQueryOptionGroup()

Check warning on line 10 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L9-L10

Added lines #L9 - L10 were not covered by tests

init {

Check warning on line 12 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L12

Added line #L12 was not covered by tests
// allow only the backends that implement the [CokoBackend] interface as subcommands
registerBackendOptions<CPGBackend>()

Check warning on line 14 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L14

Added line #L14 was not covered by tests
}

override fun getExecutor(goodFindings: Boolean, pedantic: Boolean, backend: Backend?) = with(executorOptions) {
CPGQueryExecutor(CPGQueryConfiguration(true), backend as CPGBackend)

Check warning on line 18 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L17-L18

Added lines #L17 - L18 were not covered by tests
}
}

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt is not ending with a new line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/CPGQuery.kt.

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

import de.fraunhofer.aisec.codyze.backends.cpg.CPGBackend
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.CpgQueryFinding
import io.github.detekt.sarif4k.Level

open abstract class CPGQuery {

Check warning on line 7 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/CPGQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/CPGQuery.kt#L7

Added line #L7 was not covered by tests


abstract val id: String

Check warning

Code scanning / detekt

Reports consecutive blank lines Warning

Needless blank line(s)
abstract val shortDescription: String
abstract val description: String
val level: Level = Level.Note
var help: String = ""
val tags: Set<String> = mutableSetOf()

Check warning on line 15 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/CPGQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/CPGQuery.kt#L13-L15

Added lines #L13 - L15 were not covered by tests

abstract fun query(backend: CPGBackend): List<CpgQueryFinding>

}

Check warning

Code scanning / detekt

Detects blank lines before rbraces Warning

Unexpected blank line(s) before "}"

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/CPGQuery.kt is not ending with a new line.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries

Check warning

Code scanning / detekt

License text is absent or incorrect. Warning

Expected license not found or incorrect in the file: /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt.

Check warning

Code scanning / detekt

Detects missing final newlines Warning

File must end with a newline (\n)

import de.fraunhofer.aisec.codyze.backends.cpg.CPGBackend
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.CpgQueryFinding
import de.fraunhofer.aisec.cpg.graph.Annotation
import de.fraunhofer.aisec.cpg.query.all
import de.fraunhofer.aisec.cpg.query.allExtended

Check warning

Code scanning / detekt

Detects unused imports Warning

Unused import

class ExampleQuery: CPGQuery() {

Check warning

Code scanning / detekt

Reports spaces around colons Warning

Missing spacing before ":"

Check warning on line 9 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt#L9

Added line #L9 was not covered by tests

override val id: String = "0"
override val shortDescription: String = "A short Query Example"
override val description: String = "This query is an example of a native cpg query that can use the cpg structure to " +

Check warning

Code scanning / detekt

Reports lines with exceeded length Warning

Exceeded max line length (120)

Check warning

Code scanning / detekt

Line detected, which is longer than the defined maximum line length in the code style. Warning

Line detected, which is longer than the defined maximum line length in the code style.

Check warning on line 13 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt#L11-L13

Added lines #L11 - L13 were not covered by tests
"identify relevant nodes"

Check warning

Code scanning / detekt

Reports mis-indented code Warning

Unexpected indentation (12) (should be 8)
val message = "An implementation for cryptographic functionality was found: "
val crypoUses:List<String> = listOf("ENCRYPT", "DECRYPT", "SIGN","VERIFY", "RANDOM", "RNG", "RAND")

Check warning

Code scanning / detekt

Reports spaces around commas Warning

Missing spacing after ","

Check warning

Code scanning / detekt

Reports spaces around colons Warning

Missing spacing after ":"

Check warning on line 16 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt#L15-L16

Added lines #L15 - L16 were not covered by tests

override fun query(backend: CPGBackend): List<CpgQueryFinding> {

val findings: MutableList<CpgQueryFinding> = mutableListOf()

Check warning

Code scanning / detekt

Reports methods that have an empty first line. Warning

First line in a method block should not be empty

Check warning on line 20 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt#L20

Added line #L20 was not covered by tests

backend.cpg.all<Annotation>
{ crypoUses.contains(it.name.localName.toUpperCase()) }
.second.forEach {
findings.add(CpgQueryFinding(message + it.name.localName, node = it, relatedNodes = listOf(it)))

Check warning on line 25 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt#L22-L25

Added lines #L22 - L25 were not covered by tests
}

return findings

Check warning on line 28 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt#L28

Added line #L28 was not covered by tests
}
}

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/codyze/codyze/codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/queries/ExampleQuery.kt is not ending with a new line.
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ include(":codyze-backends:cpg")
include(":codyze-specification-languages:coko:coko-core")
include(":codyze-specification-languages:coko:coko-dsl")

// Including the nativ cpg dsl queries
include(":codyze-specification-languages:cpg-native")

/*
* Optional and experimental features
*/
Expand Down
Loading