-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat(backend): tenanted assets #3206
Conversation
✅ Deploy Preview for brilliant-pasca-3e80ec ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -14,7 +14,8 @@ export async function truncateTables( | |||
'knex_migrations', | |||
'knex_migrations_lock', | |||
'knex_migrations_backend', | |||
'knex_migrations_backend_lock' | |||
'knex_migrations_backend_lock', | |||
'tenants' // So we do not truncate the operator tenant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise, we lose the operator tenant in the tenants table, and we can't insert any assets (leading to almost all tests to fail, basically).
8cfb09f
to
c2a2563
Compare
c2a2563
to
25f6248
Compare
25f6248
to
5dce25b
Compare
7696f5e
to
5a31294
Compare
// For tests, we still need to get the tenant in the middleware, but | ||
// we don't need to verify the signature nor prevent replay attacks | ||
koa.use( | ||
this.config.env !== 'test' | ||
? tenantSignatureMiddleware | ||
: testTenantSignatureMiddleware | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, had an issue where the replay attack prevention via redis (ie canApiSignature
function) was resulting a 401 Unauthorized error for many resolver tests (for cases where we call the same resolver back to back)
6399d96
to
b4ad6b7
Compare
b4ad6b7
to
557e78a
Compare
6538887
to
f3eadec
Compare
51ea55e
to
0fe4d19
Compare
0fe4d19
to
d3fa2b2
Compare
assetService.getPage({ | ||
pagination, | ||
sortOrder, | ||
tenantId: ctx.tenant.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing in tenant id
@@ -42,9 +43,13 @@ describe('Tenant Service', (): void => { | |||
let config: IAppConfig | |||
let apolloClient: ApolloClient<NormalizedCacheObject> | |||
let knex: Knex | |||
const dbSchema = 'tenant_service_test_schema' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows us to have the tenant service tests run cleanly without dropping the tenants table other tests are using
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my PR, I have updated the truncateTables to not delete the tenant.
#3152
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I also added a way to configure db schema, because for the tenant service tests, we do want to truncate the tenants table. But then of course, we break all of the other tests :) so I needed to isolate it somehow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that. I will merge yours into mine @mkurapov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good. Have a couple of queries regarding conflicting functionality.
getPage: (pagination: Pagination, sortOrder?: SortOrder) => | ||
assetService.getPage({ | ||
pagination, | ||
sortOrder, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkurapov Will you have a look at what I said here:
#3152 (comment)
We may want to use that mechanism of being able to provide alternative tenantId
for the operator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might even be worth allowing no tenant filtering if the requester is an operator
const asset = await assetService.getByCodeAndScale({ | ||
code: args.code, | ||
scale: args.scale, | ||
tenantId: ctx.tenant.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also see:
#3152 (comment)
@@ -93,7 +105,8 @@ export const updateAsset: MutationResolvers<ApolloContext>['updateAsset'] = | |||
const assetOrError = await assetService.update({ | |||
id: args.input.id, | |||
withdrawalThreshold: args.input.withdrawalThreshold ?? null, | |||
liquidityThreshold: args.input.liquidityThreshold ?? null | |||
liquidityThreshold: args.input.liquidityThreshold ?? null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see: #3152 (comment)
@@ -168,6 +181,7 @@ export const deleteAsset: MutationResolvers<ApolloContext>['deleteAsset'] = | |||
const assetService = await ctx.container.use('assetService') | |||
const assetOrError = await assetService.delete({ | |||
id: args.input.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see: #3152 (comment)
@@ -42,9 +43,13 @@ describe('Tenant Service', (): void => { | |||
let config: IAppConfig | |||
let apolloClient: ApolloClient<NormalizedCacheObject> | |||
let knex: Knex | |||
const dbSchema = 'tenant_service_test_schema' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my PR, I have updated the truncateTables to not delete the tenant.
#3152
# Conflicts: # packages/backend/src/app.ts # packages/backend/src/tenants/service.test.ts
Changes proposed in this pull request
tenantId
in aset delete, update, getPage methods (optional inget
)Checking the correct asset is used during wallet address creation will be done in #3114
Context
Fixes #3033
Checklist
fixes #number
user-docs
label (if necessary)