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

feat: strict mode to validate input for INSERT, UPDATE and UPSERT #384

Merged
merged 28 commits into from
Jan 30, 2024

Conversation

larslutz96
Copy link
Contributor

@larslutz96 larslutz96 commented Dec 13, 2023

Add a strict mode to validate input for INSERT, UPDATE and UPSERT.
This "strict" mode is a configuration that can be turned on, e. g. cds.env.features.db_strict.

strict mode to validate INSERT, UPDATE and UPSERT
db-service/lib/SQLService.js Outdated Show resolved Hide resolved
db-service/lib/SQLService.js Outdated Show resolved Hide resolved
@@ -0,0 +1,105 @@
const cds = require('../../../test/cds.js')
Copy link
Contributor

Choose a reason for hiding this comment

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

This test should probably be inside test/compliance. That way it would also be included inside the other database services their tests.

db-service/lib/SQLService.js Outdated Show resolved Hide resolved
test/scenarios/bookshop/strictMode.test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@BobdenOs BobdenOs left a comment

Choose a reason for hiding this comment

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

db-service/lib/SQLService.js Outdated Show resolved Hide resolved
@larslutz96
Copy link
Contributor Author

What about https://github.com/cap-js/cds-dbs/pull/384/files#r1427978987 ?

when i set the feature flag cds.env.features.db_strict to true its also enabled for the other test required inside the compliance folder. Therefore i moved the test to sqlite/general and required it for the other db services.

@patricebender patricebender changed the title feat: strict mode feat: strict mode to validate input for INSERT, UPDATE and UPSERT Dec 20, 2023
@larslutz96 larslutz96 requested a review from BobdenOs December 22, 2023 11:05
@@ -0,0 +1,5 @@
using {complex} from '../db/index.cds';

service ComplianceService {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this really required ?

Copy link
Contributor

@danjoa danjoa left a comment

Choose a reason for hiding this comment

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

Instead of upfront extra loops, I always prefer to put such checks into the code which has to loop anyways

db-service/lib/SQLService.js Outdated Show resolved Hide resolved
db-service/lib/SQLService.js Show resolved Hide resolved
db-service/lib/SQLService.js Outdated Show resolved Hide resolved
db-service/lib/SQLService.js Outdated Show resolved Hide resolved
db-service/lib/SQLService.js Outdated Show resolved Hide resolved
@larslutz96
Copy link
Contributor Author

larslutz96 commented Jan 23, 2024

Instead of upfront extra loops, I always prefer to put such checks into the code which has to loop anyways

@danjoa updated the code according to your suggestions

@larslutz96 larslutz96 requested a review from danjoa January 23, 2024 13:04
@larslutz96 larslutz96 merged commit 4644483 into main Jan 30, 2024
4 checks passed
@larslutz96 larslutz96 deleted the feat-strict-mode branch January 30, 2024 13:56
@cap-bots cap-bots mentioned this pull request Jan 30, 2024
patricebender pushed a commit that referenced this pull request Feb 2, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>db-service: 1.6.0</summary>

##
[1.6.0](db-service-v1.5.1...db-service-v1.6.0)
(2024-02-02)


### Added

* Add fallback for @cap-js/hana for unknown entities
([#403](#403))
([e7dd6de](e7dd6de))
* SELECT returns binaries as Buffers
([#416](#416))
([d4240d5](d4240d5))
* SELECT returns LargeBinaries as streams unless feature flag
"stream_compat" is set
([#251](#251))
([8165a4a](8165a4a))
* strict mode to validate input for `INSERT`, `UPDATE` and `UPSERT`
([#384](#384))
([4644483](4644483))
* Support Readable Streams inside INSERT.entries
([#343](#343))
([f6faf89](f6faf89))


### Fixed

* **`cqn4sql`:** only transform list if necessary
([#438](#438))
([8a7ec65](8a7ec65))
* always generate unique subquery aliases
([#435](#435))
([c875b7d](c875b7d))
* consider `list` in `from.where`
([#429](#429))
([3288e94](3288e94))
* **cqn2sql:** $user.locale refs
([#431](#431))
([ec55276](ec55276))
* **cqn4sql:** expand structured keys in on-conditions
([#421](#421))
([b1e0677](b1e0677))
* Do not generate UUIDs for association keys
([#398](#398))
([9970e14](9970e14))
* enumeration issue with session context in @cap-js/hana
([#399](#399))
([8106a20](8106a20))
* make @cap-js/sqlite work with [email protected]
([#422](#422))
([44c0a59](44c0a59))
* pass context of navigation for list within infix filter
([#433](#433))
([0ca077f](0ca077f))
* Restore former deep upsert behavior / error
([#406](#406))
([284b1e3](284b1e3))
* Skip virtual fields on UPSERTs
([#405](#405))
([1a05dcb](1a05dcb))
* sqlite date string compatibility parsing only for valid dates
([#410](#410))
([2a8bb2d](2a8bb2d)),
closes [#409](#409)
* UPSERT for @cap-js/hana for entities with multiple keys
([#418](#418))
([9bbac6e](9bbac6e))
</details>

<details><summary>sqlite: 1.5.0</summary>

##
[1.5.0](sqlite-v1.4.0...sqlite-v1.5.0)
(2024-02-02)


### Added

* SELECT returns LargeBinaries as streams unless feature flag
"stream_compat" is set
([#251](#251))
([8165a4a](8165a4a))
* Support Readable Streams inside INSERT.entries
([#343](#343))
([f6faf89](f6faf89))


### Fixed

* config in streaming test with compat flag
([#412](#412))
([335a178](335a178))
* Do not generate UUIDs for association keys
([#398](#398))
([9970e14](9970e14))
* make @cap-js/sqlite work with [email protected]
([#422](#422))
([44c0a59](44c0a59))
* sqlite date string compatibility parsing only for valid dates
([#410](#410))
([2a8bb2d](2a8bb2d)),
closes [#409](#409)
* UPSERT for @cap-js/hana for entities with multiple keys
([#418](#418))
([9bbac6e](9bbac6e))
</details>

<details><summary>postgres: 1.5.0</summary>

##
[1.5.0](postgres-v1.4.1...postgres-v1.5.0)
(2024-02-02)


### Added

* SELECT returns LargeBinaries as streams unless feature flag
"stream_compat" is set
([#251](#251))
([8165a4a](8165a4a))
* Support Readable Streams inside INSERT.entries
([#343](#343))
([f6faf89](f6faf89))


### Fixed

* switch Postgres from json to jsonb
([#402](#402))
([c98a964](c98a964))
* UPSERT for @cap-js/hana for entities with multiple keys
([#418](#418))
([9bbac6e](9bbac6e))
</details>

<details><summary>hana: 0.0.4</summary>

##
[0.0.4](hana-v0.0.3...hana-v0.0.4)
(2024-02-02)


### Added

* Add fallback for @cap-js/hana for unknown entities
([#403](#403))
([e7dd6de](e7dd6de))
* SELECT returns binaries as Buffers
([#416](#416))
([d4240d5](d4240d5))
* SELECT returns LargeBinaries as streams unless feature flag
"stream_compat" is set
([#251](#251))
([8165a4a](8165a4a))
* Support Readable Streams inside INSERT.entries
([#343](#343))
([f6faf89](f6faf89))


### Fixed

* Ensure globally unique aliases with large expand queries
([#396](#396))
([c1df747](c1df747))
* enumeration issue with session context in @cap-js/hana
([#399](#399))
([8106a20](8106a20))
* ignore empty order by
([#392](#392))
([a69fed0](a69fed0))
* improve `!=` and `==` implementation for @cap-js/hana
([#426](#426))
([9b7b5a0](9b7b5a0))
* show clear error message when unable to load project package.json
([#419](#419))
([2ebf783](2ebf783))
* UPSERT for @cap-js/hana for entities with multiple keys
([#418](#418))
([9bbac6e](9bbac6e))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: sjvans <[email protected]>
@cap-bots cap-bots mentioned this pull request Jul 18, 2024
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