Skip to content

Commit

Permalink
Fix OPA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccampo133 committed Mar 29, 2024
1 parent 69c1731 commit 54baeac
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 270 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build CLI Docker Image

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
env:
PROJECT_VERSION: 1.0.0-alpha
steps:
- uses: actions/checkout@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
run: docker build . --file Dockerfile
22 changes: 22 additions & 0 deletions .github/workflows/opa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run OPA Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Setup OPA
uses: open-policy-agent/setup-opa@v2
with:
version: latest

- name: Run OPA Tests
run: opa test classification/rego/*.rego -v
62 changes: 32 additions & 30 deletions classification/rego/address_test.rego
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
package classifier_address

test_no_label {
output.column == "UNLABELED" with input as {"column":"invalid"}
import rego.v1

test_no_label if {
output.column == false with input as {"column":"invalid"}
}

test_column_name_state {
output.state == "ADDRESS" with input as {"state":"AZ"}
test_column_name_state if {
output.state == true with input as {"state":"AZ"}
}

test_insensitive_column_name_state {
output.STATE == "ADDRESS" with input as {"STATE":"AZ"}
test_insensitive_column_name_state if {
output.STATE == true with input as {"STATE":"AZ"}
}

test_column_name_address {
output.address == "ADDRESS" with input as {"address":"123 some street"}
test_column_name_address if {
output.address == true with input as {"address":"123 some street"}
}

test_insensitive_column_name_address {
output.ADDRESS == "ADDRESS" with input as {"ADDRESS":"123 some street"}
test_insensitive_column_name_address if {
output.ADDRESS == true with input as {"ADDRESS":"123 some street"}
}

test_column_name_contains_address {
output.some_address_here == "ADDRESS" with input as {"some_address_here":"123 some street"}
test_column_name_contains_address if {
output.some_address_here == true with input as {"some_address_here":"123 some street"}
}

test_insensitive_column_name_contains_address {
output.some_ADDRESS_Here == "ADDRESS" with input as {"some_ADDRESS_Here":"123 some street"}
test_insensitive_column_name_contains_address if {
output.some_ADDRESS_Here == true with input as {"some_ADDRESS_Here":"123 some street"}
}

test_column_name_street {
output.street == "ADDRESS" with input as {"street":"123 some street"}
test_column_name_street if {
output.street == true with input as {"street":"123 some street"}
}

test_insensitive_column_name_street {
output.STREET == "ADDRESS" with input as {"STREET":"123 some street"}
test_insensitive_column_name_street if {
output.STREET == true with input as {"STREET":"123 some street"}
}

test_column_name_starts_with_street {
output.street_name == "ADDRESS" with input as {"street_name":"123 some street"}
test_column_name_starts_with_street if {
output.street_name == true with input as {"street_name":"123 some street"}
}

test_insensitive_column_name_starts_with_street {
output.STREET_Name == "ADDRESS" with input as {"STREET_Name":"123 some street"}
test_insensitive_column_name_starts_with_street if {
output.STREET_Name == true with input as {"STREET_Name":"123 some street"}
}

test_column_name_zip {
output.zip == "ADDRESS" with input as {"zip":"11111"}
test_column_name_zip if {
output.zip == true with input as {"zip":"11111"}
}

test_insensitive_column_name_zip {
output.ZIP == "ADDRESS" with input as {"ZIP":"11111"}
test_insensitive_column_name_zip if {
output.ZIP == true with input as {"ZIP":"11111"}
}

test_column_name_zipcode {
output.zipcode == "ADDRESS" with input as {"zipcode":"11111"}
test_column_name_zipcode if {
output.zipcode == true with input as {"zipcode":"11111"}
}

test_insensitive_column_name_zipcode {
output.ZIPCODE == "ADDRESS" with input as {"ZIPCODE":"11111"}
test_insensitive_column_name_zipcode if {
output.ZIPCODE == true with input as {"ZIPCODE":"11111"}
}
38 changes: 20 additions & 18 deletions classification/rego/age_test.rego
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
package classifier_age

test_no_label {
output.column == "UNLABELED" with input as {"column":"invalid"}
import rego.v1

test_no_label if {
output.column == false with input as {"column":"invalid"}
}

test_column_name_age_invalid_age {
output.age == "UNLABELED" with input as {"age":"120"}
test_column_name_age_invalid_age if {
output.age == false with input as {"age":"120"}
}

test_insensitive_column_name_age_invalid {
output.AGE == "UNLABELED" with input as {"AGE":"120"}
test_insensitive_column_name_age_invalid if {
output.AGE == false with input as {"AGE":"120"}
}

test_column_name_age_single_digit {
output.age == "AGE" with input as {"age":"1"}
test_column_name_age_single_digit if {
output.age == true with input as {"age":"1"}
}

test_insensitive_column_name_age_single_digit {
output.AGE == "AGE" with input as {"AGE":"1"}
test_insensitive_column_name_age_single_digit if {
output.AGE == true with input as {"AGE":"1"}
}

test_column_name_age_double_digit {
output.age == "AGE" with input as {"age":"10"}
test_column_name_age_double_digit if {
output.age == true with input as {"age":"10"}
}

test_insensitive_column_name_age_double_digit {
output.AGE == "AGE" with input as {"AGE":"10"}
test_insensitive_column_name_age_double_digit if {
output.AGE == true with input as {"AGE":"10"}
}

test_column_name_age_triple_digit {
output.age == "AGE" with input as {"age":"100"}
test_column_name_age_triple_digit if {
output.age == true with input as {"age":"100"}
}

test_insensitive_column_name_age_triple_digit {
output.AGE == "AGE" with input as {"AGE":"100"}
test_insensitive_column_name_age_triple_digit if {
output.AGE == true with input as {"AGE":"100"}
}
26 changes: 14 additions & 12 deletions classification/rego/ccn_test.rego
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package classifier_ccn

test_no_label {
output.column == "UNLABELED" with input as {"column":"invalid"}
import rego.v1

test_no_label if {
output.column == false with input as {"column":"invalid"}
}

test_valid_amex_ccn {
output.message == "CCN" with input as {"message":"370136066365291"}
test_valid_amex_ccn if {
output.message == true with input as {"message":"370136066365291"}
}

test_valid_visa_ccn {
output.message == "CCN" with input as {"message":"4613688275707134"}
test_valid_visa_ccn if {
output.message == true with input as {"message":"4613688275707134"}
}

test_valid_mastercard_ccn {
output.message == "CCN" with input as {"message":"5423909386888564"}
test_valid_mastercard_ccn if {
output.message == true with input as {"message":"5423909386888564"}
}

# TODO : Fix pattern to match
test_valid_mastercard_ccn {
output.message == "CCN" with input as {"message":"2701306282695666"}
test_valid_mastercard_ccn if {
output.message == true with input as {"message":"2701306282695666"}
}

test_valid_discover_ccn {
output.message == "CCN" with input as {"message":"6536673682309236"}
test_valid_discover_ccn if {
output.message == true with input as {"message":"6536673682309236"}
}
30 changes: 16 additions & 14 deletions classification/rego/cvv_test.rego
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
package classifier_cvv

test_cvv_key {
output.CVV == "CVV" with input as {"CVV":"test"}
import rego.v1

test_cvv_key if {
output.CVV == true with input as {"CVV":"test"}
}

test_cvv_key {
output.cvv == "CVV" with input as {"cvv":"test"}
test_cvv_key if {
output.cvv == true with input as {"cvv":"test"}
}

test_cvv_key {
output.CvV == "CVV" with input as {"CvV":"test"}
test_cvv_key if {
output.CvV == true with input as {"CvV":"test"}
}

test_cvv_pattern {
output.message == "CVV" with input as {"message":"451"}
test_cvv_pattern if {
output.message == true with input as {"message":"451"}
}

test_cvv_pattern {
output.message == "CVV" with input as {"message":"5061"}
test_cvv_pattern if {
output.message == true with input as {"message":"5061"}
}

test_cvv_pattern {
output.message == "CVV" with input as {"message":"123"}
test_cvv_pattern if {
output.message == true with input as {"message":"123"}
}

test_cvv_pattern {
output.message == "UNLABELED" with input as {"message":"12345"}
test_cvv_pattern if {
output.message == false with input as {"message":"12345"}
}
Loading

0 comments on commit 54baeac

Please sign in to comment.