Skip to content

Commit

Permalink
chore: remove secret scanner (microsoft#2048)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhamilton723 authored Aug 11, 2023
1 parent 8f794c8 commit c6d5882
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,4 @@ object Secrets {
lazy val ServiceConnectionSecret: String = getSecret("service-connection-secret")
lazy val ServicePrincipalClientId: String = getSecret("service-principal-clientId")

lazy val SecretRegexpFile: String = getSecret("secret-regexp-file")
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,56 +382,6 @@ class FuzzingTest extends TestBase {
}
}

test("Scan codebase for secrets") {
val excludedFiles = List(
".png",
".jpg",
".jpeg")
val excludedDirs = List(
".git",
".idea",
"target",
".docusaurus",
"node_modules",
s"website${File.separator}build"
)

val regexps: List[Regex] = using(Source.fromURL(Secrets.SecretRegexpFile)) { s =>
s.getLines().toList.map(_.r)
}.get

val allFiles = Files.walk(BuildInfo.baseDirectory.getParentFile.toPath)
.iterator().asScala.map(_.toFile)
.filterNot(f => excludedDirs.exists(dir => f.toString.contains(dir)))
.toList

val nameIssues = allFiles.flatMap {
case f if regexps.flatMap(_.findFirstMatchIn(f.toString)).nonEmpty =>
Some(s"Bad file name: ${f.toString}")
case _ =>
None
}
val contentsIssue = allFiles.filter(_.isFile)
.filterNot(f => excludedFiles.exists(end => f.toString.endsWith(end)))
.flatMap { f =>
println(f)
try {
val lines = using(Source.fromFile(f)) { s => s.getLines().toList }.get
lines.zipWithIndex.flatMap { case (l, i) =>
if (regexps.flatMap(_.findFirstMatchIn(l)).nonEmpty) {
Some(s"Line $i of file ${f.toString} contains secrets")
} else {
None
}
}
} catch {
case _: MalformedInputException => List()
}
}
val allIssues = nameIssues ++ contentsIssue
assert(allIssues.isEmpty, allIssues.mkString("\n"))
}

private def assertOrLog(condition: Boolean, hint: String = "",
disableFailure: Boolean = disableFailure): Unit = {
if (disableFailure && !condition) println(hint)
Expand Down

0 comments on commit c6d5882

Please sign in to comment.