Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove exchangeId from submit endpoint paths #182

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/http-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class TbdexHttpClient {

await message.verify()

const { to: pfiDid, exchangeId, kind } = message.metadata
const { to: pfiDid, kind } = message.metadata
const pfiServiceEndpoint = await TbdexHttpClient.getPfiServiceEndpoint(pfiDid)
const apiRoute = `${pfiServiceEndpoint}/exchanges/${exchangeId}/${kind}`
const apiRoute = `${pfiServiceEndpoint}/exchanges/${kind}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only add ${kind} if not RFQ


let response: Response
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client/tests/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('client', () => {
expect(e.statusCode).to.exist
expect(e.details).to.exist
expect(e.recipientDid).to.equal(pfiDid.uri)
expect(e.url).to.equal(`https://localhost:9000/exchanges/${rfq.metadata.exchangeId}/rfq`)
expect(e.url).to.equal(`https://localhost:9000/exchanges/rfq`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for creating an exchange, this should be https://localhost:9000/exchanges?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(e.url).to.equal(`https://localhost:9000/exchanges/rfq`)
expect(e.url).to.equal(`https://localhost:9000/exchanges`)

}
})

Expand Down
6 changes: 3 additions & 3 deletions packages/http-server/src/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@
listen(port: number | string, callback?: () => void) {
const { offeringsApi, exchangesApi, pfiDid } = this

this.api.post('/exchanges/:exchangeId/rfq', (req: Request, res: Response) =>
this.api.post('/exchanges/rfq', (req: Request, res: Response) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.api.post('/exchanges/rfq', (req: Request, res: Response) =>
this.api.post('/exchanges', (req: Request, res: Response) =>

createExchange(req, res, {
callback: this.callbacks['rfq'],
offeringsApi,
exchangesApi,
})

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
)

this.api.post('/exchanges/:exchangeId/order', (req: Request, res: Response) =>
this.api.post('/exchanges/order', (req: Request, res: Response) =>
submitOrder(req, res, {
callback: this.callbacks['order'],
exchangesApi
})
)

this.api.post('/exchanges/:exchangeId/close', (req: Request, res: Response) =>
this.api.post('/exchanges/close', (req: Request, res: Response) =>
submitClose(req, res,{
callback: this.callbacks.close,
exchangesApi,
Expand Down
22 changes: 11 additions & 11 deletions packages/http-server/tests/create-exchange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
})

it('returns a 400 if no request body is provided', async () => {
const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method: 'POST'
})

Expand All @@ -38,7 +38,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
})

it('returns a 400 if request body is not a valid json object', async () => {
const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : '!@!#'
})
Expand All @@ -59,7 +59,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid })
await rfq.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq: rfq, replyTo: 'foo' })
})
Expand All @@ -81,7 +81,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
const order = await DevTools.createOrder({ sender: aliceDid, receiver: pfiDid })
await order.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq: order })
})
Expand All @@ -103,7 +103,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid })
// deliberately omit rfq.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq })
})
Expand All @@ -127,7 +127,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {

(api.exchangesApi as InMemoryExchangesApi).addMessage(rfq)

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq })
})
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
})
await rfq.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq })
})
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
})
await rfq.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq })
})
Expand Down Expand Up @@ -303,7 +303,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
})

it('returns a 202 if RFQ is accepted', async () => {
const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq })
})
Expand All @@ -318,7 +318,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {
})
api.onSubmitRfq(callbackSpy)

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq })
})
Expand All @@ -343,7 +343,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {

const replyTo = 'https://tbdex.io/example'

const resp = await fetch('http://localhost:8000/exchanges/123/rfq', {
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const resp = await fetch('http://localhost:8000/exchanges/rfq', {
const resp = await fetch('http://localhost:8000/exchanges', {

method : 'POST',
body : JSON.stringify({ rfq, replyTo })
})
Expand Down
22 changes: 11 additions & 11 deletions packages/http-server/tests/submit-close.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
})

it('returns a 400 if no request body is provided', async () => {
const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method: 'POST'
})

Expand All @@ -37,7 +37,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
})

it('returns a 400 if request body is not a valid json object', async () => {
const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : '!@!#'
})
Expand All @@ -57,7 +57,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
const rfq = DevTools.createRfq({
sender: alice
})
const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(rfq)
})
Expand All @@ -84,7 +84,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
data: {}
})
await close.sign(alice)
const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close)
})
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
data: {}
})
await close2.sign(alice)
const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close2)
})
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
})


const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close)
})
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
})
await close.sign(alice)

const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close)
})
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
})
await close.sign(pfi)

const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close)
})
Expand Down Expand Up @@ -279,7 +279,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
})
await close.sign(imposter)

const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close)
})
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
const callbackSpy = Sinon.spy(() => Promise.resolve())
api.onSubmitClose(callbackSpy)

const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close)
})
Expand Down Expand Up @@ -349,7 +349,7 @@ describe('POST /exchanges/:exchangeId/close', () => {
const callbackSpy = Sinon.spy(() => Promise.resolve())
api.onSubmitClose(callbackSpy)

const resp = await fetch('http://localhost:8000/exchanges/123/close', {
const resp = await fetch('http://localhost:8000/exchanges/close', {
method : 'POST',
body : JSON.stringify(close)
})
Expand Down
18 changes: 9 additions & 9 deletions packages/http-server/tests/submit-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
})

it('returns a 400 if no request body is provided', async () => {
const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method: 'POST'
})

Expand All @@ -37,7 +37,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
})

it('returns a 400 if request body is not a valid json object', async () => {
const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : '!@!#'
})
Expand All @@ -63,7 +63,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
}
})
await order.sign(aliceDid)
const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : JSON.stringify(order)
})
Expand All @@ -87,7 +87,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
const rfq = await DevTools.createRfq({ sender: aliceDid, receiver: pfiDid })
await rfq.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : JSON.stringify(rfq)
})
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
})
// deliberately omit await order.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : JSON.stringify(order)
})
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
})
await order.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : JSON.stringify(order)
})
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
})
await order.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : JSON.stringify(order)
})
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('POST /exchanges/:exchangeId/order', () => {
})
await order.sign(aliceDid)

const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : JSON.stringify(order)
})
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('POST /exchanges/:exchangeId/order', () => {

api.onSubmitOrder(callbackSpy)

const resp = await fetch('http://localhost:8000/exchanges/123/order', {
const resp = await fetch('http://localhost:8000/exchanges/order', {
method : 'POST',
body : JSON.stringify(order)
})
Expand Down
Loading