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

Cover CAP's Fluent API to construct cds.ql queries #29

Merged
merged 74 commits into from
Jan 19, 2024

Conversation

jeongsoolee09
Copy link
Contributor

@jeongsoolee09 jeongsoolee09 commented Aug 14, 2023

Model CAP's Fluent API that constructs CQL query objects. This PR aims to cover all API combinations of the following:

  • SELECT
    • .one
    • .distinct
    • .columns() (including SELECT itself behaving as a shortcut for it)
    • .from()
    • .alias()
    • .where()
    • .having()
    • .groupBy()
    • .orderBy()
    • .limit()
    • .forUpdate()
    • .forShareLock()
  • INSERT
    • .into()
    • .entries() (including INSERT itself behaving as a shortcut for it)
    • .values()
    • .rows()
    • .as()
  • DELETE
    • .from()
    • .where()
  • UPDATE
    • .entity() (including UPDATE itself behaving as a shortcut for it)
    • .set()
    • .with()
    • .where()
  • UPSERT
    • .into()
    • .entries()(including UPSERT itslef behaving as a shortcut for it)

What this PR does not cover:

  • Full CQL language: e.g. CQL `SELECT col1, col2, col3 from Table`;
  • CQN objects which are canonical forms of the CQL language: e.g.
var select = {
  SELECT: {
    distinct: true,
    columns: [{ ref: ["Foo"] }, { ref: ["Boo"] }, { ref: ["Moo"] }],
    from: { ref: ["Bar"] },
    limit: {
      rows: { val: 7 },
    },
    where: [{ ref: ["col1"] }, ">", { val: 2 }],
    groupBy: [{ ref: ["col1"] }, { ref: ["col2", "prop2"] }],
  },
};

This PR also adds some modelling for the CDS custom in source Service modelling

It covers:

and request handlers registered in user definitions of services, but remains to be tested on if it will miss ones that are added later, for example
one consideration for this is , for RequestSource implementation, do we need to actually ever know which service the handler is associated to?

It does not cover:

  • RemoteService
  • MessagingService
  • DatabaseService
  • SqlService

Lastly this PR adds a basic SQL injection query that uses the above models (ie request objects received in event handlers that end up in CQL SQL statements and are run)

@jeongsoolee09 jeongsoolee09 self-assigned this Aug 16, 2023
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@rvermeulen rvermeulen left a comment

Choose a reason for hiding this comment

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

First iteration. Most important part is that we need to properly represent CQL expression clauses as we are now mixing those with expressions themselves.

The parent relationship between CQL expression clauses is not correct and that needs to be addressed. The predicate getAnAncestorCqlExpr is not equal to the transitive closure of getCqlParentExpr.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

isolate each test type
for case when objects are obtained
through ql member of cds module
@knewbury01 knewbury01 requested a review from mbaluda January 9, 2024 19:15
add extra sink for await on sql stmt
and improve test for that
also add metadata to query
Copy link
Contributor

@mbaluda mbaluda left a comment

Choose a reason for hiding this comment

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

The modelling of CQL and CDS looks good to me as well as the tests.
The sqlinjection query can be improved in future PRs
Maybe you could add QLDoc to CQL.qll entities?

@knewbury01 knewbury01 enabled auto-merge January 18, 2024 17:14
@knewbury01 knewbury01 requested a review from rvermeulen January 19, 2024 20:30
@rvermeulen rvermeulen dismissed their stale review January 19, 2024 22:09

Deferred review to @mbaluda

@knewbury01 knewbury01 merged commit 47c9219 into main Jan 19, 2024
8 checks passed
@knewbury01 knewbury01 deleted the jeongsolee09/CAP-first-draft branch January 19, 2024 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants