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

OPA inspect command failing after version upgrade on mock-tests for remote/external function dependencies #6812

Closed
surajupadhyay01 opened this issue Jun 11, 2024 · 3 comments · Fixed by #6824
Labels

Comments

@surajupadhyay01
Copy link

Short description

We have observed a deviation in the OPA CLI command: inspect, after we upgraded from OPA CLI version: 0.56.0 to version: 0.65.0.
The inspect command is passing in OPA CLI version 0.56.0 while failing for the version 0.65.0, when we have a remote rego function dependency, and it is mocked in the test files.

Steps To Reproduce

Rego files directory structure:

Attached the required files to the issue for reference

Below are the file contents:

  1. remote-function-error/remote-dependency/remote-policy.rego
package some_remote_package.policy

# This function takes in number and returns true if it is even else false
is_even(num) {
    print("Checking if number: ", num, " is even or not")
    num % 2 == 0
    print(num, " is even")
    true
} else {
    print(num, "is not even")
    false
}
  1. remote-function-error/local-policy/policy.rego
package remote.function.error.policy

import data.some_remote_package.policy.is_even as is_even


# Calls the remote `is_even()` function in a way it will return true. So the output would be true
pdp = output {
    print("At PDP")
    is_even(0) == true
    print("is_even() returned true")
    output = true
} else = output {
    print("is_even() returned false")
    output = false
}
  1. remote-function-error/local-policy/policy_test.rego
package remote.function.error.policy

# Mock the remote `is_even()` function to return false when argument '0' is passed
mock_is_even(0) := false

test_pdp = test_result {
    print("test-pdp")
    response := pdp
                with data.some_remote_package.policy.is_even as mock_is_even

    print("Response received: ", response)
    response == false
    print("Test passed with mock function")
    test_result = true
} else {
    print("Test failed with mock function")
    test_result = false
}

OPA CLI INSPECT command outputs

CLI Command: .\opa-0.56.exe inspect .\remote-function-error\local-policy
Output:

NAMESPACES:
+-----------------------------------+----------------------------------------------------+
|             NAMESPACE             |                        FILE                        |
+-----------------------------------+----------------------------------------------------+
| data.remote.function.error.policy | remote-function-error\local-policy\policy.rego     |
|                                   | remote-function-error\...l-policy\policy_test.rego |
+-----------------------------------+----------------------------------------------------+

CLI Command: .\opa-0.65.exe inspect .\remote-function-error\local-policy
Output:

error: 1 error occurred: remote-function-error\local-policy\policy_test.rego:9: rego_type_error: undefined ref: data.remote.function.error.policy.mock_is_even
        data.remote.function.error.policy.mock_is_even
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        have: (number) => boolean
@philipaconrad
Copy link
Contributor

This is could be related to #6457, I think? @johanfylling might know more. 🤔

@johanfylling
Copy link
Contributor

@philipaconrad, yes, this looks like it could be an unsolved edge case to the issue fixed in #6457.

@surajupadhyay01
Copy link
Author

surajupadhyay01 commented Jun 12, 2024

Yes, the similar cases are mentioned in issues: #6457 and #6591

johanfylling added a commit to johanfylling/opa that referenced this issue Jun 13, 2024
Fixing issue where policies containing `with` replacing unknown functions can't be inspected.

Fixes: open-policy-agent#6812
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants