Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[CM T0] Correct the behavior for length plugin #4312

Closed
Gratla opened this issue Apr 3, 2022 · 3 comments · Fixed by #4363
Closed

[CM T0] Correct the behavior for length plugin #4312

Gratla opened this issue Apr 3, 2022 · 3 comments · Fixed by #4363
Assignees

Comments

@Gratla
Copy link
Contributor

Gratla commented Apr 3, 2022

Expected behavior

  • checker plugins should run their validation during ...Get() and ...Set().
  • If a validation problem occurs during ...Set(), the plugin should set an error and return -1
  • If a validation problem occurs during ...Get(), the plugin should add a warning and continue validation (finally return 0)
  • plugins need to have the placements: pregetstorage and postgetstorage in their metadata. Otherwise ...Get()/...Set() won't be called.

The behaviour needs to be fixed in the following file:
https://github.com/ElektraInitiative/libelektra/blob/master/src/plugins/length/length.c

Subissue for #4059.

@mandoway
Copy link
Contributor

mandoway commented Apr 3, 2022

I reproduced the issue following the tutorial on the plugin page:

$ sudo apt update
$ sudo apt install libelektra5-experimental

$ sudo kdb mount test.ni /tests/length length ni
$ sudo kdb meta-set spec:/tests/length/text check/length/max 3

// This is expected and correct
$ kdb set user:/tests/length/text asda
Sorry, module length issued the error C03200:
Validation Semantic: Length check of key 'user:/tests/length/text' with value 'asda' failed. Maximum length is 3 but the given string has length 4

$ kdb set user:/tests/length/text asd
Create a new key user:/tests/length/text with string "asd"


// Edit the file to contain a string with more than 3 characters
$ kdb file user:/tests/length/text
/home/markus/.config/test.ni
$ sudo nano /home/markus/.config/test.ni

// This command should actually return a warning
$ kdb get /tests/length/text
asda

@kodebach
Copy link
Member

kodebach commented Apr 3, 2022

Great to see #4059 is slowly getting done.

@kodebach
Copy link
Member

kodebach commented Apr 3, 2022

// Edit the file to contain a string with more than 3 characters
$ kdb file user:/tests/length/text
/home/markus/.config/test.ni
$ sudo nano /home/markus/.config/test.ni

A minor thing, but the part above could be replaced with the following to make the snippet work without additional user input:

$ sudo sed -i 's/text = asd/text = 1234/g' $(kdb file user:/tests/length/text)

Also, when posting reproduction snippets you don't need to include the apt update and apt install commands. We'll automatically assume you used the latest release of Elektra.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants