<!-- PR description--> **Changes** * Introduce jwt expiry checks, to be used in a later PR. Based off @vkamra's idea. * Add an url parsing helper func to extract the value of specified query param(e.g. `tempauth`). * Unit tests for both above. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [x] 🕐 Yes, but in a later PR - [ ] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup - [x] Optimization #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * internal #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package common_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/alcionai/corso/src/internal/common"
|
|
"github.com/alcionai/corso/src/internal/tester"
|
|
)
|
|
|
|
type URLUnitSuite struct {
|
|
tester.Suite
|
|
}
|
|
|
|
func TestURLUnitSuite(t *testing.T) {
|
|
suite.Run(t, &URLUnitSuite{Suite: tester.NewUnitSuite(t)})
|
|
}
|
|
|
|
func (suite *URLUnitSuite) TestGetQueryParamFromURL() {
|
|
qp := "tempauth"
|
|
table := []struct {
|
|
name string
|
|
rawURL string
|
|
queryParam string
|
|
expectedResult string
|
|
expect assert.ErrorAssertionFunc
|
|
}{
|
|
{
|
|
name: "valid",
|
|
rawURL: "http://localhost:8080?" + qp + "=h.c.s&other=val",
|
|
queryParam: qp,
|
|
expectedResult: "h.c.s",
|
|
expect: assert.NoError,
|
|
},
|
|
{
|
|
name: "query param not found",
|
|
rawURL: "http://localhost:8080?other=val",
|
|
queryParam: qp,
|
|
expect: assert.Error,
|
|
},
|
|
{
|
|
name: "empty query param",
|
|
rawURL: "http://localhost:8080?" + qp + "=h.c.s&other=val",
|
|
queryParam: "",
|
|
expect: assert.Error,
|
|
},
|
|
// In case of multiple occurrences, the first occurrence of param is returned.
|
|
{
|
|
name: "multiple occurrences",
|
|
rawURL: "http://localhost:8080?" + qp + "=h.c.s&other=val&" + qp + "=h1.c1.s1",
|
|
queryParam: qp,
|
|
expectedResult: "h.c.s",
|
|
expect: assert.NoError,
|
|
},
|
|
}
|
|
|
|
for _, test := range table {
|
|
suite.Run(test.name, func() {
|
|
t := suite.T()
|
|
|
|
_, flush := tester.NewContext(t)
|
|
defer flush()
|
|
|
|
token, err := common.GetQueryParamFromURL(test.rawURL, test.queryParam)
|
|
test.expect(t, err)
|
|
|
|
assert.Equal(t, test.expectedResult, token)
|
|
})
|
|
}
|
|
}
|