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

More testing for SQL trickery #109

Merged
merged 1 commit into from
Oct 25, 2024
Merged

More testing for SQL trickery #109

merged 1 commit into from
Oct 25, 2024

Conversation

crisptrutski
Copy link
Collaborator

@crisptrutski crisptrutski commented Oct 25, 2024

This PR improves the ergonomics for adding queries which all have the same error, and uses that to add a bunch more "skullduggery detected" fixtures.

Unfortunately I realize that a case has slipped through, and the fix is non-trivial. Needs further discussion.

Also fixed an issue where the "all the components" function was not actually catching JSQLParser exceptions.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @crisptrutski and the rest of your teammates on Graphite Graphite

@@ -11,15 +11,6 @@

(set! *warn-on-reflection* true)

(def broken-queries
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since errors are values now, we don't need this.

"The fixtures in merged fixtures file, mapped by their identifiers."
[]
(->> (str/split (slurp merged-fixtures-file) #"-- FIXTURE: ")
;; TODO generically detect queries.<namespace>.sql files
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for a 3rd file before bothering.

@@ -0,0 +1,5 @@
SELECT 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "implicit semicolons" tests are unrelated.

Smuggling them in before the 5.0 upgrade, which will affect how this is handled.

EXECUTE stmt('table_name');

-- FIXTURE: variable
-- BROKEN
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the permissions perspective, broken is still fine.

CALL user_function('table_name');

-- FIXTURE: select-function
SELECT user_function('table_name');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case we don't handle, and is a potential blocker.

On the other hand, we do block the ability to create such a malicious (or just naive) function via Metabase.

Since we can't anticipate all user functions, we may need an allow list on expressions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean you can only escape Metabase permissions if somebody with better access had prepared some function for you? That makes sense, but also maybe we really want to be able to configure a whitelist for allowed functions?

Comment on lines -91 to +95
(or (get global-overrides mode)
(get-in ns-overrides [mode (namespace fixture)])
(get-in expected-cs [:overrides mode :error])
(or (get-in expected-cs [:overrides mode :error])
(get-in expected-cs [:overrides mode ck])
(when-keyword (get-in expected-cs [:overrides mode]))))
(when-keyword (get-in expected-cs [:overrides mode]))
(get-in ns-overrides [mode (namespace fixture)])
(get global-overrides mode)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a bug in my overrides, and at first thought it was precedence. I think with this change its more intuitive anyway though.

(catch AnalysisError e
(->macaw-error e))
(catch JSQLParserException e
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moved into parsed-query

(catch AnalysisError e
(->macaw-error e))
(catch JSQLParserException e
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not working, as the exception is thrown while building the argument for this function.

@@ -1030,32 +1026,32 @@ public void visit(Alter alter) {

@Override
public void visit(Statements stmts) {
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
throw new AnalysisError(AnalysisErrorType.INVALID_QUERY);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any plans to support statements AFAIK, can update this if that changes.

@crisptrutski crisptrutski changed the title More dynamic testing. Find a case we don't handle yet More testing for SQL trickery Oct 25, 2024
@crisptrutski crisptrutski requested review from piranha and a team October 25, 2024 11:13
@crisptrutski crisptrutski marked this pull request as ready for review October 25, 2024 11:14
@crisptrutski crisptrutski self-assigned this Oct 25, 2024
@crisptrutski crisptrutski merged commit 0110ed3 into master Oct 25, 2024
5 checks passed
Copy link
Collaborator Author

Merge activity

  • Oct 25, 7:52 AM EDT: A user merged this pull request with Graphite.

@crisptrutski crisptrutski deleted the more-dynamic-tests branch October 25, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants