Esempio n. 1
0
func TestRSAEncryptedNoOrFailedPassword(t *testing.T) {
	jm, err := ctxjwt.NewService(ctxjwt.WithRSAFromFile(pkFile))
	assert.EqualError(t, err, ctxjwt.ErrPrivateKeyNoPassword.Error())
	assert.Nil(t, jm)

	jm2, err2 := ctxjwt.NewService(ctxjwt.WithRSAFromFile(pkFile, []byte(`adfasdf`)))
	assert.EqualError(t, err2, x509.IncorrectPasswordError.Error())
	assert.Nil(t, jm2)
}
Esempio n. 2
0
func TestNewDefault(t *testing.T) {
	jm, err := ctxjwt.NewService()
	assert.NoError(t, err)
	assert.Equal(t, time.Hour, jm.Expire)

	assert.Nil(t, jm.Blacklist.Set("test", time.Hour))
	assert.False(t, jm.Blacklist.Has("test"))

	assert.Len(t, jm.JTI.Get(), uuidLen)

	testClaims := map[string]interface{}{
		"mascot": "gopher",
	}
	theToken, jti, err := jm.GenerateToken(testClaims)
	assert.NoError(t, err)
	assert.Empty(t, jti)
	assert.NotEmpty(t, theToken)

	haveToken, err := jm.Parse(theToken)
	assert.NoError(t, err)
	assert.True(t, haveToken.Valid)
	assert.Equal(t, "gopher", haveToken.Claims["mascot"])

	failedToken, err := jm.Parse(theToken + "c")
	assert.Error(t, err)
	assert.Nil(t, failedToken)

	jmRSA, err := ctxjwt.NewService(ctxjwt.WithRSAFromFile("invalid.key"))
	assert.Nil(t, jmRSA)
	assert.Contains(t, err.Error(), "open invalid.key: no such file or directory")
}
Esempio n. 3
0
func TestRSAWithoutPassword(t *testing.T) {
	pkFileNP := filepath.Join(build.Default.GOPATH, "src", "github.com", "corestoreio", "csfw", "net", "ctxjwt", "test_rsa_np")
	testRsaOption(t, ctxjwt.WithRSAFromFile(pkFileNP))
}
Esempio n. 4
0
func TestRSAEncryptedPassword(t *testing.T) {
	pw := []byte("cccamp")
	testRsaOption(t, ctxjwt.WithRSAFromFile(pkFile, pw))
}