Skip to content

Module to create, manage and use personal tokens when interacting with Jahia's GraphQL api

License

Notifications You must be signed in to change notification settings

Jahia/personal-api-tokens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Module ID Store
Tests Case Management
CI / CD CircleCI Unit Tests Integration Tests Build Snapshot Build Release
Artifacts Snapshot Release
Slack Discussion Notifications
Jahia logo

Personal API Tokens

A module to create, manage and use personal tokens when interacting with Jahia API

Table of content

Presentation

Dev environment

Build

Use mvn install to build the module.

Installation

Module

Deploy the module in your Jahia instance.

Usage

Token generation

After building the project, you can generate a new random token by calling :

java -jar target/personal-api-tokens-1.0.0-SNAPSHOT-cli.jar

You can also get the token key of an existing token by typing :

java -jar target/personal-api-tokens-1.0.0-SNAPSHOT-cli.jar --get-key hHSppWmiQgmZ6KrUDR/w8VbEbsi/m08OlMiviLhIUfM=

GraphQL API

The module provides a Graphql API extension, that will allow to manipulate tokens. You will find all fields related to personal API token and their documentation in query/admin/personalApiTokens

For example it's possible to create a token by calling :

mutation {
  admin {
    personalApiTokens {
      createToken(userId:"root", name:"my token", expireAt:"2020-12-12")
    }
  }
}

And to get its data with :

query {
  admin {
    personalApiTokens {
     token(token:"aJC9l44cSKGv4Xvb0Qc8o/V1Say1s77k0Q046/VIwo8=") {
       key
       name
       user {
         name
       }
     }
    }
  }
}

## E2E tests

End-to-End tests are located in the test folder, you can take the following approaches to execute the test suite:

### Towards an existing Jahia

You can run the test suite towards an existing and pre-configured Jahia instance by running the following:

```bash 
cd tests/
yarn
CYPRESS_baseUrl=http://localhost:8080 JAHIA_USERNAME=root JAHIA_PASSWORD=root yarn e2e:debug

This will open-up Cypress in dev mode, allowing you to select which tests to run. As you modify test files, the tests are automatically re-executed for the selected suite.

Using Docker

You can use Docker and docker-compose to simply run the entire test suite.

Environment Variables

The following environment variables are available for executing the tests using docker.

Variable Description
MANIFEST Manifest file detailing how the environment should be provisioned from a fresh Jahia image. The TESTS_IMAGE ship by default with a set of manifest covering various use cases (built module, snapshot module from nexus, built module from the store, ...)
TESTS_IMAGE Test image to run (for example: jahia/personal-api-tokens:1.0.0), Test images are releases alongside module releases and contain the release artifacts. It is useful if you want to test a particular module version with a specific Jahia version
JAHIA_IMAGE Docker image of Jahia to be started (for example: jahia/jahia-dev:8.0.1.0)
JAHIA_URL The base url to connect to Jahia (usually http://jahia:8080)
JAHIA_HOST Host running the Jahia server (usually localhost)
JAHIA_PORT Port for the Jahia server (usually 8080)
JAHIA_USERNAME Username to log into Jahia
JAHIA_PASSWORD Password to log into Jahia
NEXUS_USERNAME Username to connect to Nexus (if you were to fetch a snapshot module)
NEXUS_PASSWORD Password to connect to Nexus (if you were to fetch a snapshot module)

Re-run an existing suite (not building images)

You might be interested in running the latest snapshot of Jahia, with the latest snapshot of the module (or any combination).

cd tests
mv .env.example .env
# Edit the environment variables based on desired test configuration
docker-compose up

From that point Jahia and the test container will start, the test container will wait for Jahia to become live, install the desired module, and run the tests

Build a new tests image

If you modified the codebase (tests or module) you might want to build a new test image (it could be just a local test image).

# If you first want to build the module, the docker build step will add the corresponding artifacts to the docker image
mvn clean install 
# To run the module in build mode, you need to install graphql-dxm-provider
mvn dependency:copy-dependencies 
# To copy the dependency for installation by jahia-cli
cp target/dependency/graphql-dxm-provider-2.2.2-SNAPSHOT.jar tests/artifacts/graphql-dxm-provider.jar 
cd tests
bash env.build.sh

Note that by default the new image name is jahia/personal-api-tokens:latest so it will take over any latest that you might already have locally. If necessary, you could either change that in env.build.sh to your desired name or simply give your image a new tag docker tag jahia/personal-api-tokens:latest jahia/personal-api-tokens:MY_NEW_TAG

Once built, the image can be used with docker-compose (see previous section).

Links