Common Utility Functions in Eureka Karate

Common Utility Functions in Eureka Karate

Each feature file contains a call setup-users.feature, which is needed to create the infrastructure that the tests will run against.

As an example

image-20250324-110454.png

There are two main points except setup-users.feature call: table modules and table userPermissions.

 

 

Explanation of setup-users.feature logic.

  • create new tenant
    use tenant.feature@create
    POST /tenants

    { "id": "some uuid", "name": "some name", "description": "some description" }
  • create entitlement

    • applicationSearch(search for application IDs that use modules from table modules

    • create entitlement
      POST /entitlements
      ?tenantParameters=loadSample=false,loadReference={true or false}
      &async=true
      &purgeOnRollback=false

    { "tenantId": "98c66555-087a-45f5-a433-3d6e52d18dd8", "applications": [ ... "app-platform-complete-1.0.0-SNAPSHOT.0000", "app-platform-minimal-1.0.0-SNAPSHOT.0000" ... ] }

 

  • get authorization token

    • extract master token from keykcloak

    • use it to extract sidecarSecret of new tenant

    • extract new tenant token

  • create test user
    POST /users-keycloak/users

    { "username": '#(userName)', "active":true, "departments": [], "proxyFor": [], "type": "patron", "personal": {"firstName":"Karate","lastName":'#("User " + userName)'} }

 

  • specify user credentials (login password)
    POST /authn/credentials

    { "username":"", "userId":"", "password":"" }

 

  • add permissions for user
    add permissions from table userPermissions
    POST /users/capabilities

    { "userId": "517a92ce-6955-4cc3-af0f-d181f69674f3", "capabilityIds": [ "f7546b5e-8688-4c70-9eb0-72835f8f0e35", "9e08b878-4638-4db2-ba1d-51374f54f2bd", "ed8b8a9b-26f5-495b-91a5-e00073780ba6", "45840c06-6f88-4046-a921-015ac90f5f1f", "a68f4084-7c01-4bf7-b8fd-859797e01de1", "eb8b7951-8461-40ca-bc21-93ffb0c63bd2" ] }