Skip to content

Improving the example test setup#32

Open
dutow wants to merge 1 commit intoPercona-Lab:mainfrom
dutow:scriptedexport
Open

Improving the example test setup#32
dutow wants to merge 1 commit intoPercona-Lab:mainfrom
dutow:scriptedexport

Conversation

@dutow
Copy link
Collaborator

@dutow dutow commented Feb 17, 2026

Previous it was just a JSON export of a realm created manually

This commit adds a script that creates this realm, and improves it by containing:

  • Two realms (pgrealm and wrongrealm)
  • Two clients (pgtest, pgtest2)
  • Two scopes (pgscope, pgscope2) on both realms
  • Two users (testuser, testuser2) on both realms Added script that recreates the current keycloak example config

It also enables the direct access grant, and adds a help CLI script that gets a token directly for testing.

"realm" : [ "offline_access", "uma_authorization" ],
"client" : {
"account" : [ "manage-account", "view-profile" ]
"account" : [ "view-profile", "manage-account" ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting that they do not sort it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, this will be fun with each update.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should write a patch. :D

echo "==> Creating realm '$realm'..."
kcadm create realms -s "realm=$realm" -s enabled=true

# kcadm doesn't handle empty-body PUTs well, so we use curl for scope assignments.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it a POST?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They refer to it as PUT everywhere in their docs: https://www.keycloak.org/docs-api/latest/rest-api/index.html

# Configure a realm with the standard test resources:
# - client scope 'pgscope'
# - client 'pgtest' (public, device flow enabled)
# - user 'testuser' (testuser@example.com / asdfasdf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this actually true? It sets up two users, two scopes, two clients?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ops, that's a stale comment

$RT cp "$EXPORT_CONTAINER:/tmp/export/pgrealm-realm.json" "$IMPORT_DIR/pgrealm.json"
$RT cp "$EXPORT_CONTAINER:/tmp/export/wrongrealm-realm.json" "$IMPORT_DIR/wrongrealm.json"

# Validate the exported JSON
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to do this?

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 guess not, I'll remove it. If we accidentally commit an error response or something like that the CI will notice, even if we do not immediately test it locally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, remove it.

PASSWORD="asdfasdf"
CLIENT="pgtest"
SCOPES="email pgscope"
HOST="https://localhost:8443"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not a that big fan of all these defaults, especially since we have multiple of each. Why do we just pick one? Do these default actually add enough value?

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 value is that you can specify only one parameter that you change, and get a different token. For example if you want to test the situation "logging in with a token from the wrong realm", you only have to specify the realm.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is cleaner if e.g. CLIENT always need to be specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How would you decide which fields we have to always specify?

Previous it was just a JSON export of a realm created manually

This commit adds a script that creates this realm, and improves it by
containing:
* Two realms (pgrealm and wrongrealm)
* Two clients (pgtest, pgtest2)
* Two scopes (pgscope, pgscope2) on both realms
* Two users (testuser, testuser2) on both realms
Added script that recreates the current keycloak example config

It also enables the direct access grant, and adds a help CLI script that
gets a token directly for testing.
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.

2 participants