-
Notifications
You must be signed in to change notification settings - Fork 81
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
Use retryable http client in Azure authz provider #372
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package azure | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"net/http/httptest" | ||
|
@@ -37,7 +38,8 @@ import ( | |
) | ||
|
||
const ( | ||
loginResp = `{ "token_type": "Bearer", "expires_in": 8459, "access_token": "%v"}` | ||
loginResp = `{ "token_type": "Bearer", "expires_in": 8459, "access_token": "%v"}` | ||
httpClientRetryCount = 2 | ||
) | ||
|
||
func clientSetup(serverUrl, mode string) (*Authorizer, error) { | ||
|
@@ -52,9 +54,10 @@ func clientSetup(serverUrl, mode string) (*Authorizer, error) { | |
} | ||
|
||
authOpts := auth.Options{ | ||
ClientID: "client_id", | ||
ClientSecret: "client_secret", | ||
TenantID: "tenant_id", | ||
ClientID: "client_id", | ||
ClientSecret: "client_secret", | ||
TenantID: "tenant_id", | ||
HttpClientRetryCount: httpClientRetryCount, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we assert that it try 2 times ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
} | ||
|
||
authzInfo := rbac.AuthzInfo{ | ||
|
@@ -171,6 +174,7 @@ func TestCheck(t *testing.T) { | |
assert.Nilf(t, resp, "response should be nil") | ||
assert.NotNilf(t, err, "should get error") | ||
assert.Contains(t, err.Error(), "Error occured during authorization check") | ||
assert.Contains(t, err.Error(), fmt.Sprintf("giving up after %d attempt", httpClientRetryCount+1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bcho @julienstroheker this line can assert that it gives up after 3 attempts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please have another round of review? Thanks |
||
if v, ok := err.(errutils.HttpStatusCode); ok { | ||
assert.Equal(t, v.Code(), http.StatusInternalServerError) | ||
} | ||
|
@@ -194,7 +198,7 @@ func TestCheck(t *testing.T) { | |
resp, err := client.Check(ctx, request, store) | ||
assert.Nilf(t, resp, "response should be nil") | ||
assert.NotNilf(t, err, "should get error") | ||
assert.Contains(t, err.Error(), "Checkaccess requests have timed out") | ||
assert.Contains(t, err.Error(), "context deadline exceeded") | ||
if v, ok := err.(errutils.HttpStatusCode); ok { | ||
assert.Equal(t, v.Code(), http.StatusInternalServerError) | ||
} | ||
|
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.
can we add a unit test for covering the retry behavior?
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.
added