From bec46e2dabb3fa7cb84e490ac941c80dda1aff5c Mon Sep 17 00:00:00 2001 From: Keith Barlow Date: Tue, 31 Oct 2023 00:52:50 -0400 Subject: [PATCH] Refactor to a constant; update unit test --- pkg/provider/browser/browser.go | 9 +++++++-- pkg/provider/browser/browser_test.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/provider/browser/browser.go b/pkg/provider/browser/browser.go index 9c3d03eee..f0da0dbcd 100644 --- a/pkg/provider/browser/browser.go +++ b/pkg/provider/browser/browser.go @@ -13,6 +13,8 @@ import ( var logger = logrus.WithField("provider", "browser") +var TimeoutPageWaitForRequest = newPageWaitForRequestOptions(300000) + // Client client for browser based Identity Provider type Client struct { Headless bool @@ -94,8 +96,7 @@ var getSAMLResponse = func(page playwright.Page, loginDetails *creds.LoginDetail } logger.Info("waiting ...") - var timeout float64 = 300000 - r, _ := page.WaitForRequest(signin_re, playwright.PageWaitForRequestOptions{Timeout: &timeout}) + r, _ := page.WaitForRequest(signin_re, TimeoutPageWaitForRequest) data, err := r.PostData() if err != nil { return "", err @@ -124,3 +125,7 @@ func (cl *Client) Validate(loginDetails *creds.LoginDetails) error { return nil } + +func newPageWaitForRequestOptions(timeout float64) playwright.PageWaitForRequestOptions { + return playwright.PageWaitForRequestOptions{Timeout: &timeout} +} diff --git a/pkg/provider/browser/browser_test.go b/pkg/provider/browser/browser_test.go index 8027215b0..05797aa7b 100644 --- a/pkg/provider/browser/browser_test.go +++ b/pkg/provider/browser/browser_test.go @@ -107,7 +107,7 @@ func TestGetSAMLResponse(t *testing.T) { regex, err := signinRegex() assert.Nil(t, err) page.Mock.On("Goto", url).Return(resp, nil) - page.Mock.On("WaitForRequest", regex).Return(req) + page.Mock.On("WaitForRequest", regex, TimeoutPageWaitForRequest).Return(req) req.Mock.On("PostData").Return(params.Encode(), nil) // loginDetails := &creds.LoginDetails{ // URL: url,