# Testing

### Local Development and Testing

For local development, you can use Ngrok to create a secure tunnel to your local environment:

1. Download Ngrok from the official website for your operating system
2. Extract and navigate to the Ngrok directory in your terminal
3. Run the command: `./ngrok http PORT_NUMBER`
   * Replace PORT\_NUMBER with your local server port (e.g., 8080 for default Spring Boot applications)
4. Copy the generated Ngrok URL to use as your webhook endpoint

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdDFaP8KMI314NV97tPsM4ohlEVgwFdMvtAxznVC01N2qLIl5rrzIEumCpSIJAdPj1O2guhUqxW4zUKvnz5_P6azHFJu7_OyCMhegiZiPP7mNPbPPld4h_TLe2K2pAOzsCjJvfzxA?key=6DlycrQMqDw4gINLP2fVn1qc" alt=""><figcaption></figcaption></figure>

### Security: Signature Verification

Every webhook request includes an `X-RR-Signature` header to verify authenticity. This signature is generated using the endpoint's secret key and the payload.

#### Verification Process

1. The signature is provided as a hexadecimal string in the `X-RR-Signature` header
2. Generate your own signature using the received payload and your secret key
3. Compare the generated signature with the received signature
4. If they match, the payload is verified as coming from Rocket Referral

#### Implementation Examples

**Java Implementation**

```java
javaCopyimport javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;

public String signedPayload(String message, String key) 
    throws NoSuchAlgorithmException, InvalidKeyException {
    Mac hmacSHA256 = Mac.getInstance("HmacSHA256");
    SecretKeySpec secretKeySpec = new SecretKeySpec(
        key.getBytes(StandardCharsets.UTF_8),
        "HmacSHA256"
    );
    hmacSHA256.init(secretKeySpec);
    return HexFormat.of().formatHex(
        hmacSHA256.doFinal(message.getBytes(StandardCharsets.UTF_8))
    );
}
```

**JavaScript Implementation**

```javascript
javascriptCopyconst crypto = require('crypto');

function signed_payload(clientKey, msg) {
    const key = new Buffer(clientKey, 'hex');
    return crypto.createHmac('sha256', key)
        .update(msg)
        .digest('hex');
}
```

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://referral-rocket.gitbook.io/docs/developer-tools/webhooks/testing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
