Skip to content

Commit

Permalink
Remove trailing slashes from endpoints (#961)
Browse files Browse the repository at this point in the history
* Remove trailing slashes from endpoints

* Sanitize registration endpoint
  • Loading branch information
raymondjacobson authored Oct 21, 2020
1 parent 1d70307 commit c9d6b66
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions libs/src/services/ethContracts/serviceProviderFactoryClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ class ServiceProviderFactoryClient extends GovernedContractClient {
}

async registerWithDelegate (serviceType, endpoint, amount, delegateOwnerWallet) {
if (!this.isDebug && !Utils.isFQDN(endpoint)) {
const sanitizedEndpoint = endpoint.replace(/\/$/, '')

if (!this.isDebug && !Utils.isFQDN(sanitizedEndpoint)) {
throw new Error('Not a fully qualified domain name!')
}
if (!Number.isInteger(amount) && !Utils.isBN(amount)) {
throw new Error('Invalid amount')
}

const requestUrl = urlJoin(endpoint, 'health_check')
const requestUrl = urlJoin(sanitizedEndpoint, 'health_check')
const axiosRequestObj = {
url: requestUrl,
method: 'get',
Expand Down Expand Up @@ -61,7 +63,7 @@ class ServiceProviderFactoryClient extends GovernedContractClient {
// Register and stake
const method = await this.getMethod('register',
Utils.utf8ToHex(serviceType),
endpoint,
sanitizedEndpoint,
amount,
delegateOwnerWallet)
const tx = await this.web3Manager.sendTransaction(method, 1000000)
Expand Down Expand Up @@ -278,7 +280,7 @@ class ServiceProviderFactoryClient extends GovernedContractClient {
const info = await method.call()
return {
owner: info.owner,
endpoint: info.endpoint,
endpoint: info.endpoint.replace(/\/$/, ''),
spID: parseInt(serviceId),
type: serviceType,
blockNumber: parseInt(info.blockNumber),
Expand Down

0 comments on commit c9d6b66

Please sign in to comment.