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

@sweir27: Allows jwts to be issued using a slug #246

Merged
merged 1 commit into from
May 11, 2016
Merged
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: 3 additions & 1 deletion schema/causality_jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default {
if (options.role === 'OPERATOR' && me.type !== 'Admin') {
throw new Error('Unauthorized to act as an operator');
}
const registered = find(bidders, (b) => b.sale._id === options.sale_id);
const registered = find(bidders, (b) => {
return (b.sale._id === options.sale_id || b.sale.id === options.sale_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible we could resolve the correct ID sooner, and avoid spreading reconciliation code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally possible, I just used this because it was a quick fix that worked locally. Resolving the actual ID sounds too complicated for me to do alone, happy to pair. However, the resolution should be done on the metaphysics side, otherwise we loose the benefit of the GraphQL code altogether.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. If we merge as is, can you ticket a task for someone who knows the system better? Just want to make sure we don't forget to come back for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was merged earlier, I'll open an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!
On May 11, 2016 20:21, "Ash Furrow" notifications@github.com wrote:

In schema/causality_jwt.js
#246 (comment):

@@ -36,7 +36,9 @@ export default {
if (options.role === 'OPERATOR' && me.type !== 'Admin') {
throw new Error('Unauthorized to act as an operator');
}

  •  const registered = find(bidders, (b) => b.sale._id === options.sale_id);
    
  •  const registered = find(bidders, (b) => {
    
  •    return (b.sale._id === options.sale_id || b.sale.id === options.sale_id);
    

Was merged earlier, I'll open an issue.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/artsy/metaphysics/pull/246/files/6d57f048e53e89c57fd04bc8f6e830ee25d450c6#r62949037

});
if (options.role === 'BIDDER' && !registered) {
throw new Error('Not registered to bid in this auction');
}
Expand Down
19 changes: 18 additions & 1 deletion test/schema/causality_jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('CausalityJWT', () => {
type: 'User',
}))
.onCall(1)
.returns(Promise.resolve([{ sale: { _id: 'foo' } }]));
.returns(Promise.resolve([{ sale: { _id: 'foo', id: 'slug' } }]));
CausalityJWT.__Rewire__('gravity', gravity);
});

Expand All @@ -47,6 +47,23 @@ describe('CausalityJWT', () => {
});
});

it('works with a sale slug', () => {
const query = `{
causality_jwt(role: BIDDER, sale_id: "slug")
}`;
return graphql(schema, query, { accessToken: 'foo' })
.then((data) => {
omit(jwt.decode(data.data.causality_jwt, HMAC_SECRET), 'iat')
.should.eql({
aud: 'auctions',
role: 'bidder',
userId: 'craig',
saleId: 'foo',
bidderId: '123',
});
});
});

it('denies a bidder not registered to the sale', () => {
const query = `{
causality_jwt(role: BIDDER, sale_id: "bar")
Expand Down