Repository: lldap/lldap (language: rust)

Issue:
[BUG] bootstrap.sh user creation fails when id is a substring of another id
**Describe the bug**

Bootstrapping users fails when one user's id contains another user's id.

**To Reproduce**

1. Prepare 2 users under "user-configs"

```shell
$ cat user-configs/1.json
{
  "id": "johndoe",
  "email": "johndoe@example.com"
}
$ cat user-configs/2.json
{
  "id": "john",
  "email": "john@example.com"
}
```

2. Execute bootstrap.sh
3. See error

```
--- johndoe ---
User "johndoe" successfully created
--- johndoe ---

--- john ---
Database error: `None of the records are updated`
jq: error (at <stdin>:0): Cannot iterate over null (null)
```

**Expected behavior**

Both users created successfully.

**Logs**

N/A

**Additional context**

Changing the order of the files ("john" before "johndoe") works.

```
--- john ---
User "john" successfully created
--- john ---

--- johndoe ---
User "johndoe" successfully created
--- johndoe ---
```


Discussion / hints:
Note that bootstrap.sh is a user-contributed script, I don't claim to understand how it works.

I would welcome a PR fixing it, though. It's just bash, so even if you can't write rust it should be doable.

Fix patch:
diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh
index b1f70964..20933ae4 100755
--- a/scripts/bootstrap.sh
+++ b/scripts/bootstrap.sh
@@ -252,7 +252,7 @@ get_users_list() {
 }
 
 user_exists() {
-  if [[ "$(get_users_list | jq --raw-output --arg id "$1" '.data.users | any(.[]; contains({"id": $id}))')" == 'true' ]]; then
+  if [[ "$(get_users_list | jq --raw-output --arg id "$1" '.data.users | any(.[]; .id == $id)')" == 'true' ]]; then
     return 0
   else
     return 1


Test patch: