-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9c7d501
commit 408f1fe
Showing
114 changed files
with
3,779 additions
and
977 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
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
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './common-tool.service'; | ||
export { CommonToolValidationService, ToolParameterTypeValidationUtil } from './validation'; | ||
export { CommonToolDeleteService } from './common-tool-delete.service'; | ||
export { Lti11EncryptionService } from './lti11-encryption.service'; |
117 changes: 117 additions & 0 deletions
117
apps/server/src/modules/tool/common/service/lti11-encryption.service.spec.ts
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { Authorization } from 'oauth-1.0a'; | ||
import { Lti11EncryptionService } from './lti11-encryption.service'; | ||
|
||
describe(Lti11EncryptionService.name, () => { | ||
let module: TestingModule; | ||
let service: Lti11EncryptionService; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [Lti11EncryptionService], | ||
}).compile(); | ||
|
||
service = module.get(Lti11EncryptionService); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
describe('sign', () => { | ||
describe('when signing with OAuth1', () => { | ||
const setup = () => { | ||
const mockKey = 'mockKey'; | ||
const mockSecret = 'mockSecret'; | ||
const mockUrl = 'https://mockurl.com/'; | ||
const testPayload: Record<string, string> = { | ||
param1: 'test1', | ||
}; | ||
|
||
return { | ||
mockKey, | ||
mockSecret, | ||
mockUrl, | ||
testPayload, | ||
}; | ||
}; | ||
|
||
it('should sign the payload with OAuth1', () => { | ||
const { mockKey, mockSecret, mockUrl, testPayload } = setup(); | ||
|
||
const result: Authorization = service.sign(mockKey, mockSecret, mockUrl, testPayload); | ||
|
||
expect(result).toEqual<Authorization>({ | ||
oauth_consumer_key: mockKey, | ||
oauth_nonce: expect.any(String), | ||
oauth_signature: expect.any(String), | ||
oauth_signature_method: 'HMAC-SHA1', | ||
oauth_timestamp: expect.any(Number), | ||
oauth_version: '1.0', | ||
...testPayload, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('verify', () => { | ||
describe('when the OAuth1 signature is valid', () => { | ||
const setup = () => { | ||
const mockKey = 'mockKey'; | ||
const mockSecret = 'mockSecret'; | ||
const mockUrl = 'https://mockurl.com/'; | ||
const testPayload: Record<string, string> = { | ||
param1: 'test1', | ||
}; | ||
|
||
const signedPayload: Authorization = service.sign(mockKey, mockSecret, mockUrl, testPayload); | ||
|
||
return { | ||
mockKey, | ||
mockSecret, | ||
mockUrl, | ||
testPayload, | ||
signedPayload, | ||
}; | ||
}; | ||
|
||
it('should return true', () => { | ||
const { mockKey, mockSecret, mockUrl, signedPayload } = setup(); | ||
|
||
const result = service.verify(mockKey, mockSecret, mockUrl, signedPayload); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when the OAuth1 signature is invalid', () => { | ||
const setup = () => { | ||
const mockKey = 'mockKey'; | ||
const mockSecret = 'mockSecret'; | ||
const mockUrl = 'https://mockurl.com/'; | ||
const testPayload: Record<string, string> = { | ||
param1: 'test1', | ||
}; | ||
|
||
const signedPayload: Authorization = service.sign(mockKey, mockSecret, mockUrl, testPayload); | ||
const tamperedPayload = { ...signedPayload, param1: 'test2' }; | ||
|
||
return { | ||
mockKey, | ||
mockSecret, | ||
mockUrl, | ||
testPayload, | ||
tamperedPayload, | ||
}; | ||
}; | ||
|
||
it('should return false', () => { | ||
const { mockKey, mockSecret, mockUrl, tamperedPayload } = setup(); | ||
|
||
const result = service.verify(mockKey, mockSecret, mockUrl, tamperedPayload); | ||
|
||
expect(result).toEqual(false); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.