Skip to content

Commit

Permalink
Replace manual token inspection by assertion in test
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas11 committed Aug 19, 2022
1 parent a28c407 commit 46da5c9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions examples/go-auth/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"log"
"fmt"
"regexp"

"github.com/pulumi/pulumi-azure-native/sdk/go/azure/authorization"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
q "github.com/ryboe/q"
)

func main() {
Expand All @@ -15,8 +15,16 @@ func main() {
return err
}

log.Println("Got OAuth token: ", tokenResult.Token[:20])
q.Q(tokenResult.Token)
// Based on the ABNF from RFC 6750:
// 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="
tokenLooksValid := regexp.MustCompile(`^[._~+/a-zA-Z0-9-]+=*$`).MatchString(tokenResult.Token)
if !tokenLooksValid {
token := tokenResult.Token
if len(token) > 40 {
token = token[:40] + "..."
}
return fmt.Errorf("Token '%s' does not seem valid", token)
}

return nil
})
Expand Down

0 comments on commit 46da5c9

Please sign in to comment.