Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Mock External Group Provider

Remold edited this page Jul 24, 2015 · 2 revisions

Can the Mock External Group Provider be used to test the external group API for any external group, or is this specific to SURFteams? If it is specific, I'm not sure this page will be helpful in the OpenConext documentation. Part of the api.demo.openconext.org is the Mock (external) Group provider that mimics an external group provider and/ or a mock api.demo.openconext.org to be used locally when developing with surfteams.

Configuration

Default behavior is to look on the classpath for a file named: json/%s-%s.json

  • In the case of a getPerson the %s-%s is resolved by replacing the first %s with the userId of the person (replacing any strange characters with "_") and the second %s with the string "person" (e.g. json/urn_collab_person_test.surfguest.nl_jjoachimsthal-person.json)
  • In the case of a getMembers the the %s-%s is resolved by replacing the first %s with the groupId of the group (replacing any strange characters with "_") and the second %s with the string "teammembers" (e.g. json/nl_surfnet_diensten_test_team-teammembers.json)
  • In the case of a getGroups the the %s-%s is resolved by replacing the first %s with the userId of the person (replacing any strange characters with "_") and the second %s with the string "groups20" (e.g. json/urn_collab_person_test.surfguest.nl_jjoachimsthal-groups20.json)

There are fallback JSON files when the specified file does not exist. The above functionality enables developers working on SURFteams to mimic specific situations.

The Mock API can also act as External Group Provider. For this to work the Mock API must be configured in manage.demo.openconext.org.

The Mock Group Provider either needs a file formatted as described at the tomcat classpath, or you can use the REST API to dynamically add groups and members to the Mock Provider.

Group Provider configuration example:

Filter conditions example:

It depends on the scenario that needs to be tested if and how the regular expressions are configured. The most simple setting is shown, where the External Group Provider kicks with each userId and not replacing any of the urns returned. This is also the setup used for the performance tests.

Basic Authentication

It is also possible to configure the mock External Group Provider as a Basic Authentication External Group Provider. The URL is:

https://api.demo.openconext.org/v1/mockbasic/social/rest/

REST interface

When the above described default behavior is not sufficient the Mock API can be injected at run-time to behave differently. It accepts REST calls to configure the state returned.

To add an user (backed by an in-memory database which does not 'survive' a tomcat restart):

curl -v -H "Accept: application/json" -H "Content-type: application/json" https://api.demo.openconext.org/v1/configure/person -X POST -d '{ "nickname": "Mister Foo","emails": [ {"value": "[email protected]", "type": "email" } ],"voot_membership_role":"member",        "id": "urn:collab:person:test.surfguest.nl:mfoo",        "name": {            "formatted": "Mister Foo",            "familyName": "Foo",            "givenName": "Mister"        },        "tags": [            "guest"        ],        "accounts": [            {                "username": "mFoo",                "userId": "mFoo"            }        ],        "organizations": [            {                "name": "test.surfguest.nl"            }        ],        "displayName": "Mister Foo"}'

To add a group:

curl -v -H "Accept: application/json" -H "Content-type: application/json" https://api.demo.openconext.org/v1/configure/group -X POST -d '{"id": "Group1", "title":"Tilte"}'

To add an user to a group:

curl -v -H "Accept: application/json" -H "Content-type: application/json" https://api.demo.openconext.org/v1/configure/person/john.doe/group1 -X POST -d '{}'

To reset the whole Mock API (and to return to the default behavior of looking for JSON files):

curl -v -H "Accept: application/json" -H "Content-type: application/json" https://api.demo.openconext.org/v1/configure/reset -X POST -d '{}'

To instruct the Mock API to respond slow (milliseconds):

curl -v -H "Accept: application/json" -H "Content-type: application/json" https://api.demo.openconext.org/v1/configure/sleep/1000 -X POST -d '{}'

When persons/ groups/ memberships are added the Mock API automatically switches from the default behavior to the pre-record state. The Mock API is not to be used simultaneously by users, because it does not use an unique identifier of an user to keep multiple configurations (for example the ip-adresses). So, if user 1 expects the default behavior and user 2 wants to use the pre-record behavior, things will get messy.

For a production and acceptance platform the Mock API can be disable by setting the property "mock-api-enabled" in api-coin.properties to false (which is the default setting).

Clone this wiki locally