github.com/twilio/twilio-go@v1.20.1/client/jwt/jwt_test.go (about)

     1  package jwt
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	. "github.com/twilio/twilio-go/client/jwt/util"
     8  )
     9  
    10  func TestGetHeaders(t *testing.T) {
    11  	jwtT := Jwt{
    12  		SecretKey: "secret",
    13  		Issuer:    "twilio",
    14  		Subject:   "twilio jwt",
    15  		Algorithm: "HS256",
    16  	}
    17  	headers := jwtT.Headers()
    18  	assert.Equal(t, HS256, headers["alg"])
    19  	assert.Equal(t, JWT, headers["typ"])
    20  }
    21  
    22  func TestGetPayload(t *testing.T) {
    23  	jwtT := Jwt{
    24  		SecretKey:      "secret",
    25  		Issuer:         "twilio",
    26  		Subject:        "twilio jwt",
    27  		Algorithm:      "HS256",
    28  		Nbf:            0,
    29  		Ttl:            0,
    30  		ValidUntil:     0,
    31  		DecodedHeaders: nil,
    32  		DecodedPayload: nil,
    33  	}
    34  
    35  	payload := map[string]interface{}{}
    36  	payload = jwtT.generatePayload(payload)
    37  	assert.Equal(t, "twilio", payload["iss"])
    38  	assert.NotZero(t, payload["exp"])
    39  	assert.NotZero(t, payload["nbf"])
    40  	assert.Equal(t, "twilio jwt", payload["sub"])
    41  }