Skip to content

Commit

Permalink
Hurl tests with CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishbowler committed Oct 9, 2024
1 parent ae85c60 commit 8900d82
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,76 @@ jobs:
secrets:
IGNITE_REALTIME_MAVEN_USERNAME: ${{ secrets.IGNITE_REALTIME_MAVEN_USERNAME }}
IGNITE_REALTIME_MAVEN_PASSWORD: ${{ secrets.IGNITE_REALTIME_MAVEN_PASSWORD }}
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout tests
uses: actions/checkout@v4
with:
sparse-checkout: |
test
- name: Checkout Openfire actions e.g. 'startCIServer'
uses: actions/checkout@v4
with:
repository: igniterealtime/Openfire
path: openfire-ci
sparse-checkout: |
.github
- name: Download a recent Openfire daily build.
run: |
# This tries to find the most recent daily build, going back 30 days if none are available.
#Note that the cache above will cause whatever build that's download to be considered 'todays' build.
for i in $(seq 0 30); do
STAMP=`date --date="$i day ago" +%F`;
echo "Attempting to download Openfire build for $STAMP"
curl --fail -L "https://download.igniterealtime.org/openfire/dailybuilds/openfire_$STAMP.tar.gz" -o openfire.tar.gz && break
done
- name: Extract Openfire
run: |
tar -xzf openfire.tar.gz
- name: Set up yq
uses: frenck/action-setup-yq@v1

- name: Copy in the extended demoboot config
run: |
rm openfire/conf/openfire.xml
cp ./test/demoboot-with-additions.xml openfire/conf/openfire-demoboot.xml
- name: Start CI server from distribution
id: startCIServer
uses: ./openfire-ci/.github/actions/startserver-action
with:
distBaseDir: './openfire'
domain: 'example.org'
ip: '127.0.0.1'

- name: Download the built artifacts
uses: actions/download-artifact@v4
with:
name: restAPI
path: .

- name: Install plugin
run: |
cp restAPI-openfire-plugin-assembly.jar openfire/plugins/restAPI.jar
- uses: gacts/install-hurl@v1

- name: Test the plugin
run: |
# Wait for the server to start
sleep 30
# Test the plugin
hurl --test test/restAPI.hurl
- name: Expose Openfire logs
uses: actions/upload-artifact@v4
if: always() # always run even if the previous step fails
with:
name: Openfire server logs
path: openfire/logs/*
11 changes: 11 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Tests

The tests contained in this folder are written in Hurl (see [docs](https://hurl.dev/docs/manual.html)).

Install Hurl with instructions as per the documentation.

Configure the Rest API:

* Enable it
* Set auth for shared key, and set the value in test.env
* Set `adminConsole.access.allow-wildcards-in-excludes` to true
64 changes: 64 additions & 0 deletions test/demoboot-with-additions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<jive>
<plugin>
<restapi>
<enabled>true</enabled>
<httpAuth>secret</httpAuth>
<secret>potato</secret>
</restapi>
</plugin>
<adminConsole>
<access>
<allow-wildcards-in-excludes>true</allow-wildcards-in-excludes>
</access>
<port>9090</port>
<securePort>9091</securePort>
</adminConsole>
<connectionProvider>
<className>org.jivesoftware.database.EmbeddedConnectionProvider</className>
</connectionProvider>
<autosetup>
<run>true</run>
<locale>en</locale>
<xmpp>
<auth>
<anonymous>true</anonymous>
</auth>
<domain>example.org</domain>
<fqdn>example.org</fqdn>
</xmpp>
<database>
<mode>embedded</mode>
</database>
<admin>
<email>[email protected]</email>
<password>admin</password>
</admin>
<users>
<user1>
<username>john</username>
<password>secret</password>
<name>John Doe</name>
<email>[email protected]</email>
<roster>
<item1>
<jid>[email protected]</jid>
<nickname>Jane</nickname>
</item1>
</roster>
</user1>
<user2>
<username>jane</username>
<password>secret</password>
<name>Jane Doe</name>
<email>[email protected]</email>
<roster>
<item1>
<jid>[email protected]</jid>
<nickname>John</nickname>
</item1>
</roster>
</user2>
</users>
</autosetup>
</jive>
101 changes: 101 additions & 0 deletions test/restAPI.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
### CLUSTERING ###

GET {{host}}/plugins/restapi/v1/clustering/status
Authorization: {{authkey}}
HTTP 200
[Asserts]
xpath "string(/clustering/status)" == "Disabled"

GET {{host}}/plugins/restapi/v1/clustering/nodes
Authorization: {{authkey}}
HTTP 200
[Asserts]
xpath "/clusterNodes[not(child::node())]" exists


### USER GROUPS ###

GET http://localhost:9090/plugins/restapi/v1/groups
Authorization: {{authkey}}
HTTP 200
[Asserts]
xpath "/groups[not(child::node())]" exists # groups at the root, with no child nodes

POST http://localhost:9090/plugins/restapi/v1/groups
Authorization: {{authkey}}
Content-Type: application/xml
```
<?xml version="1.0" encoding="UTF-8"?>
<group>
<name>group1</name>
<description>test-group</description>
<shared>false</shared>
<admins>
<admin>jane</admin>
</admins>
<members>
<member>john</member>
</members>
</group>
```
HTTP 201

GET http://localhost:9090/plugins/restapi/v1/groups # check if the group was created
Authorization: {{authkey}}
HTTP 200
[Asserts]
xpath "/groups/group[name='group1']" exists

GET http://localhost:9090/plugins/restapi/v1/groups/group1
Authorization: {{authkey}}
HTTP 200
[Asserts]
xpath "/group[name='group1']" exists
xpath "string(/group/description)" == "test-group"

PUT http://localhost:9090/plugins/restapi/v1/groups/group1
Authorization: {{authkey}}
Content-Type: application/xml
```
<?xml version="1.0" encoding="UTF-8"?>
<group>
<name>group1</name>
<description>test-group-updated</description>
<shared>false</shared>
<admins>
<admin>jane</admin>
</admins>
<members>
<member>john</member>
</members>
</group>
```
HTTP 200

GET http://localhost:9090/plugins/restapi/v1/groups/group1
Authorization: {{authkey}}
HTTP 200
[Asserts]
xpath "/group[name='group1']" exists
xpath "string(/group/description)" == "test-group-updated"

DELETE http://localhost:9090/plugins/restapi/v1/groups/group1
Authorization: {{authkey}}
HTTP 200


### CHAT ROOMS ###
GET http://localhost:9090/plugins/restapi/v1/chatrooms
Authorization: {{authkey}}
HTTP 200

GET http://localhost:9090/plugins/restapi/v1/sessions
Authorization: {{authkey}}
HTTP 200
[Asserts]
xpath "/sessions[not(child::node())]" count == 1 # sessions at the root, with no child nodes


GET http://localhost:9090/plugins/restapi/v1/system/readiness/server
Authorization: {{authkey}}
HTTP 200
2 changes: 2 additions & 0 deletions test/test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
host=http://localhost:9090
authkey=potato

0 comments on commit 8900d82

Please sign in to comment.