github.com/grailbio/base@v0.0.11/cmd/ticket-server/googleblesser_test.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache-2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"strings"
     9  	"testing"
    10  )
    11  
    12  func TestCheckClaims(t *testing.T) {
    13  	googleBlesserInit([]string{"grailbio.com", "contractors.grail.com"})
    14  
    15  	cases := []struct {
    16  		claims    claims
    17  		errPrefix string
    18  	}{
    19  		{claims{HostedDomain: "grailbio.com", EmailVerified: true, Email: "user@grailbio.com"}, ""},
    20  		{claims{HostedDomain: "grailbio.com", EmailVerified: true, Email: "user@contractors.grail.com"}, ""},
    21  		{claims{}, "ID token doesn't have a verified email"},
    22  		{claims{EmailVerified: false}, "ID token doesn't have a verified email"},
    23  		{claims{EmailVerified: true, Email: "user@grailbio.com"}, "ID token has a wrong hosted domain:"},
    24  		{claims{HostedDomain: "grailbio.com", EmailVerified: true, Email: "user@gmail.com"}, "ID token does not have a sufix with a authorized email domain"},
    25  		{claims{HostedDomain: "grailbio.com", EmailVerified: true, Email: "user@gmail@.com"}, "ID token does not have a sufix with a authorized email domain"},
    26  	}
    27  
    28  	for _, c := range cases {
    29  		err := c.claims.checkClaims()
    30  		if err != nil && (c.errPrefix == "" || !strings.HasPrefix(err.Error(), c.errPrefix)) {
    31  			t.Errorf("checkClaims(%+v): got %q, want prefix %q", c.claims, err, c.errPrefix)
    32  		}
    33  	}
    34  }