Skip to content

nokamoto/webpush-testing-service

Repository files navigation

webpush-testing-service

CircleCI

overview

Usage

Run

docker run -p 9000:9000 nokamoto13/webpush-testing-service:0.0.0

This will start the service with the default applicationServerKey.

To configure applicationServerKey, pass -DapplicationServerKey=${YOUR_VAPID_PUBLIC_KEY} to the docker command line argument.

docker run -p 9000:9000 nokamoto13/webpush-testing-service:0.0.0 -DapplicationServerKey=${YOUR_VAPID_PUBLIC_KEY}

Test

  1. Call POST /testing/:driver to start a new browser. This API returns id and subscription.

    POST http://localhost:9000/testing/firefox

    {
      "id":"f6cdb052-c412-426f-bcd6-3cc54b8a3903",
      "subscription":{
        "endpoint":"https://updates.push.services.mozilla.com/wpush/v2/...",
        "auth":"MTYemr59rcxqaODIf3byeA==",
        "p256dh":"BL/DHX+aV4dlVwQG2YE/w7VogSJj+lJZvNRNiHoL+OTPKjhxZCXomNeUNLEkuLvt8SVGvnec+gn/JNQ1fYyjdP0=",
      }
    }
  2. Send a webpush message with your client. The message must be JSON and have id field.

    POST https://updates.push.services.mozilla.com/wpush/v2/...

    {
      "id": "f6cdb052-c412-426f-bcd6-3cc54b8a3903",
      "options": {
        "body": "test message"
      }
    }

    The service worker will eventually receive the message from the push service (i.e. mozilla) and store the event to the testing service.

  3. Call GET /testing/:id to retrieve the message.

    GET http://localhost:9000/testing/f6cdb052-c412-426f-bcd6-3cc54b8a3903

    {
      "events":[
        "{\"id\":\"f6cdb052-c412-426f-bcd6-3cc54b8a3903\",\"options\":{\"body\":{\"test message\"}}}"
      ]
    }

Here is a concrete example test code in Scala.

API

POST /testing/:driver

Start a new browser.

Request
driver firefox or chrome
Status
201
400 if :driver undefined
Response JSON Field
id an unique suite id
driver firefox or chrome
subscription.endpoint PushSubscription.endpoint
subscription.auth PushSubscription.getKey('auth')
subscription.p256dh PushSubscription.getKey('p256dh')

GET /testing/:id

Retrieve webpush messages that the browser received.

Status
200
404 if :id not found
Response JSON Field
driver firefox or chrome
events a list of PushEvent.data.text()

DELETE /testing/:id

Quit the browser.

Status
204

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published