-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add unauthenticated user token lookup test
- Loading branch information
Showing
1 changed file
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import * as grpc from '@grpc/grpc-js'; | |
import { updateConfig } from '@restorecommerce/acs-client'; | ||
import { | ||
UserServiceDefinition, | ||
UserServiceClient, User, DeepPartial | ||
UserServiceClient, User, DeepPartial, UserType | ||
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user'; | ||
import { | ||
RoleServiceDefinition, | ||
|
@@ -1826,6 +1826,75 @@ describe('testing identity-srv', () => { | |
await userService.unregister({ identifier: 'test.user1' }); | ||
}); | ||
}); | ||
|
||
describe('testing unauthenticated users', function registerUser(): void { | ||
it('should create unauthenticated users and retrieve their tokens', async () => { | ||
const aaaa = await userService.create({items: [ | ||
{ | ||
id: 'example-unauthenticated-user', | ||
active: true, | ||
user_type: UserType.TECHNICAL_USER, | ||
name: 'exampleuser', | ||
email: '[email protected]', | ||
first_name: 'unauthenticated', | ||
last_name: 'unauthenticated', | ||
properties: [ | ||
{ | ||
id: 'urn:restorecommerce:acs:names:network:src:domain', | ||
value: 'example.com' | ||
} | ||
], | ||
tokens: [ | ||
{ | ||
name: 'unauthenticated_token', | ||
token: 'aaaa' | ||
} | ||
] | ||
}, | ||
{ | ||
id: 'foo-unauthenticated-user', | ||
active: true, | ||
user_type: UserType.TECHNICAL_USER, | ||
name: 'unauthenticated', | ||
email: '[email protected]', | ||
first_name: 'unauthenticated', | ||
last_name: 'unauthenticated', | ||
properties: [ | ||
{ | ||
id: 'urn:restorecommerce:acs:names:network:src:domain', | ||
value: 'foo.com' | ||
} | ||
], | ||
tokens: [ | ||
{ | ||
name: 'unauthenticated_token', | ||
token: 'bbbb' | ||
} | ||
] | ||
} | ||
]}); | ||
|
||
const exampleToken = await userService.getUnauthenticatedSubjectTokenForTenant({ | ||
domain: 'example.com' | ||
}); | ||
|
||
exampleToken.token.should.equal('aaaa'); | ||
|
||
const fooToken = await userService.getUnauthenticatedSubjectTokenForTenant({ | ||
domain: 'foo.com' | ||
}); | ||
|
||
fooToken.token.should.equal('bbbb'); | ||
|
||
const missingToken = await userService.getUnauthenticatedSubjectTokenForTenant({ | ||
domain: 'hello.com' | ||
}); | ||
|
||
missingToken.should.deepEqual({}); | ||
|
||
await userService.delete({ ids: ['example-unauthenticated-user', 'foo-unauthenticated-user'] }); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |