Skip to content

Commit

Permalink
feat: tests for language detection (#532)
Browse files Browse the repository at this point in the history
secureli-XXX

<!-- Include general description here -->


## Changes
<!-- A detailed list of changes -->
*

## Testing
<!--
Mention updated tests and any manual testing performed.
Are aspects not yet tested or not easily testable?
Feel free to include screenshots if appropriate.
 -->
*

## Clean Code Checklist
<!-- This is here to support you. Some/most checkboxes may not apply to
your change -->
- [ ] Meets acceptance criteria for issue
- [ ] New logic is covered with automated tests
- [ ] Appropriate exception handling added
- [ ] Thoughtful logging included
- [ ] Documentation is updated
- [ ] Follow-up work is documented in TODOs
- [ ] TODOs have a ticket associated with them
- [ ] No commented-out code included


<!--
Github-flavored markdown reference:
https://docs.github.com/en/get-started/writing-on-github
-->

---------

Co-authored-by: isaac-heist-slalom <isaac.heist@slalom.com>
  • Loading branch information
ambhrin-slalom and isaac-heist-slalom committed Apr 26, 2024
1 parent 7fcc283 commit 454ec28
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 20 deletions.
36 changes: 18 additions & 18 deletions .secureli/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.0
hooks:
- id: black
- repo: https://github.com/yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.1
hooks:
- id: black
- repo: https://github.com/yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lint = "black --check ."
precommit = "pre-commit run --config .secureli/.pre-commit-config.yaml --all-files"
test = ["init", "lint", "coverage_run", "coverage_report"]
e2e = "bats --verbose-run tests/end-to-end"
lang-test = "bats --verbose-run tests/end-to-end/test-language-detect.bats"

[tool.poetry.dependencies]
# Until `python-dependency-injector` supports python 3.12, restrict to python 3.11 and lower
Expand Down
2 changes: 1 addition & 1 deletion secureli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def version_callback(value: bool):
config = pre_commit_abstr.get_pre_commit_config(path)

all_repos = [
(hook.id, repo.rev.lstrip("v"))
(hook.id, repo.rev.lstrip("v") if repo.rev else None)
for repo in config.repos
for hook in repo.hooks
]
Expand Down
2 changes: 1 addition & 1 deletion secureli/modules/shared/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PreCommitRepo(BaseModel):
"""

url: str = Field(alias="repo")
rev: str
rev: Optional[str]
hooks: list[PreCommitHook] = Field(default=[])
suppressed_hook_ids: list[str] = Field(default=[])

Expand Down
9 changes: 9 additions & 0 deletions tests/end-to-end/test-data/Csharp_Sample/src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}
7 changes: 7 additions & 0 deletions tests/end-to-end/test-data/Go_Sample/src/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello, world!")
}
11 changes: 11 additions & 0 deletions tests/end-to-end/test-data/JavaScript_Sample/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript_Sample</title>
</head>
<body>
<script src="index.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions tests/end-to-end/test-data/JavaScript_Sample/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello, world!");
1 change: 1 addition & 0 deletions tests/end-to-end/test-data/Kotlin_Sample/src/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fun main() { println("Hello, world!") }
1 change: 1 addition & 0 deletions tests/end-to-end/test-data/Python_Sample/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, world!")
1 change: 1 addition & 0 deletions tests/end-to-end/test-data/Swift_Sample/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, world!")
1 change: 1 addition & 0 deletions tests/end-to-end/test-data/Terraform_Sample/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output "hello_world" { value = "Hello, world!" }
1 change: 1 addition & 0 deletions tests/end-to-end/test-data/TypeScript_Sample/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello, world!");
56 changes: 56 additions & 0 deletions tests/end-to-end/test-language-detect.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
setup() {
load "${BATS_LIBS_ROOT}/bats-support/load"
load "${BATS_LIBS_ROOT}/bats-assert/load"
}

# Tests currently commented out as they have a dependency on test data which will be workied on in a future ticket. In order to run them currently, you would need to go into
# each one of the language repo folder under test-data folder and git initialize them. In the future we wish to automate the creation and git initialization of each one of these
# folders

#@test "can detect C# language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/Csharp_Sample/
# assert_output --partial '[seCureLI] The following language(s) support secrets detection: C#'
# assert_output --partial '[seCureLI] - C#: 100%'
#}

#@test "can detect Go language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/Go_Sample/
# assert_output --partial '[seCureLI] - Go: 100%'
# assert_output --partial '[seCureLI] seCureLI has been installed successfully for the following language(s): Go.'
#}

#@test "can detect Javascript language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/JavaScript_Sample/
# assert_output --partial '[seCureLI] - JavaScript: 100%'
# assert_output --partial '[seCureLI] seCureLI has been installed successfully for the following language(s): JavaScript.'
#}

#@test "can detect Kotlin language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/Kotlin_Sample/
# assert_output --partial '[seCureLI] - Kotlin: 100%'
# assert_output --partial '[seCureLI] seCureLI has been installed successfully for the following language(s): Kotlin.'
#}

#@test "can detect Python language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/Python_Sample/
# assert_output --partial '[seCureLI] - Python: 100%'
# assert_output --partial '[seCureLI] seCureLI has been installed successfully for the following language(s): Python.'
#}

#@test "can detect Swift language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/Swift_Sample/
# assert_output --partial '[seCureLI] seCureLI has been installed successfully for the following language(s): Swift.'
# assert_output --partial '[seCureLI] - Swift: 100%'
#}

#@test "can detect Terraform language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/Terraform_Sample/
# assert_output --partial '[seCureLI] - Terraform: 100%'
# assert_output --partial '[seCureLI] seCureLI has been installed successfully for the following language(s): Terraform.'
#}

#@test "can detect Typescript language" {
# run python secureli/main.py init -ryd tests/end-to-end/test-data/Typescript_Sample/
# assert_output --partial '[seCureLI] - TypeScript: 100%'
# assert_output --partial '[seCureLI] seCureLI has been installed successfully for the following language(s): TypeScript.'
#}

0 comments on commit 454ec28

Please sign in to comment.