Skip to content

Commit

Permalink
update testsuite for token expiration checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aaperis committed Jan 23, 2025
1 parent 679536b commit cb8bd2f
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"crypto/rsa"
"fmt"
"io"
"log"
"os"
"runtime"
Expand Down Expand Up @@ -326,10 +327,40 @@ func (suite *HelperTests) TestTokenExpiration() {
err = CheckTokenExpiration(token)
assert.EqualError(suite.T(), err, "the provided access token has expired, please renew it")

// Token with valid expiration
token = generateDummyToken(time.Now().Add(time.Hour * 72).Unix())
// Token with valid expiration, less than 2 hours
token = generateDummyToken(time.Now().Add(time.Hour).Unix())

storeStderr := os.Stderr
r, w, _ := os.Pipe()
os.Stderr = w

err = CheckTokenExpiration(token)
assert.NoError(suite.T(), err)

w.Close()
out, _ := io.ReadAll(r)
os.Stderr = storeStderr

msg := "WARNING! The provided access token expires in only 0 hours and 59 minutes."
assert.Contains(suite.T(), string(out), msg)

// Token with valid expiration, more than a day
exp := time.Now().Add(time.Hour * 72)
token = generateDummyToken(exp.Unix())

storeStderr = os.Stderr
r, w, _ = os.Pipe()
os.Stderr = w

err = CheckTokenExpiration(token)
assert.NoError(suite.T(), err)

w.Close()
out, _ = io.ReadAll(r)
os.Stderr = storeStderr

msg = "The provided access token expires on " + exp.Format("2006-01-02")
assert.Contains(suite.T(), string(out), msg)
}

func (suite *HelperTests) TestPubKeyEmptyField() {
Expand Down

0 comments on commit cb8bd2f

Please sign in to comment.