-
Notifications
You must be signed in to change notification settings - Fork 0
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: dio client interceptor #5
Conversation
thorvalld
commented
Mar 15, 2024
- Added Dio Client interception
resolved, clockskew adjusted and test case added
@jeanplevesque I still haven't received any change requests yet! |
I haven't had time to check yet. I'll try to look soon. |
|
||
// Register the mock response | ||
dioAdapter.onGet(baseEndpoint, (request) { | ||
options.disableAutoRetryOnClockSkew |
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.
Like I said before, the mocked server doesn't know about the configuration of the interceptor so it's weird that you check it. The test server should behave the same no matter the test case.
At high level, the test server must always do the same thing: it returns an unauthorized response when the HMAC signature is invalid and a ok response when the HMAC signature is valid. In order to be valid, the timestamp part of the signature must match the one of the server.
expect(response.requestOptions.headers, contains(headerName)); | ||
}); | ||
|
||
test('Interceptor returns OK with auto-retry tuned to false', () async { |
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.
Interceptor returns OK with auto-retry tuned to false
What is this testing?
When the auto-retry is false, it means that the interceptor must not adjust its timestamps using the clock skew. The result of this should be that you ultimately get an unauthorized response from the server.
To get an OK response, you would have to send a valid signature, which implies that you wouldn't need the auto-retry mechanism anyways.
|
||
dioAdapter.onGet(baseEndpoint, (request) { | ||
requestCount++; | ||
request.reply(HttpStatus.ok, emptyDataInjection); |
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 thing here, it doesn't make sense for you to return an OK if you want to test the auto-retry mechanisms. For the interceptor to consider auto-retrying, you need an unauthorized in the first place.
dio.interceptors.add(interceptor); | ||
|
||
dioAdapter.onGet(baseEndpoint, (request) { | ||
request.reply(HttpStatus.ok, {}); |
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.
Again, if your server always return OK, how are you testing the validity of the timestamp of the signature?
I'm taking over this feature. I'm closing this PR in favor on this one #7 |