Skip to content

Possible to write rego tests for masks? #507

Discussion options

You must be logged in to vote

Hey, sorry for the late reply here. Masking of data is 'just' a Rego policy, so it'd be possible to test the behaviour like this:

masks.rego

package system.log

mask["/input/password"] {
	input.input.resource == "user"
}

mask["/input/ssn"]

masks_test.rego

package system.log

import future.keywords.in

test_password_present_for_user {
	result := mask with input as {"input": {"resource": "user", "password": "foobar"}}

	"/input/password" in result
}

test_ssn_always_present {
	result := mask with input as {}

	"/input/ssn" in result
}

and to test

$ opa test  *.rego
masks_test.rego:
data.system.log.test_password_present_for_user: PASS (409.583µs)
data.system.log.test_ssn_always_present: PAS…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@leefernandes
Comment options

@charlieegan3
Comment options

Answer selected by leefernandes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants