Exemple #1
0
func TestRSAEncryptedNoOrFailedPassword(t *testing.T) {
	jm, err := userjwt.New(userjwt.SetRSAFromFile(pkFile))
	assert.Contains(t, err.Error(), "Private Key is encrypted but password was not set")
	assert.Nil(t, jm)

	jm2, err2 := userjwt.New(userjwt.SetRSAFromFile(pkFile, []byte(`adfasdf`)))
	assert.Contains(t, err2.Error(), "Private Key decryption failed: x509: decryption password incorrect")
	assert.Nil(t, jm2)
}
Exemple #2
0
func TestNewDefault(t *testing.T) {
	jm, err := userjwt.New()
	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.Equal(t, userjwt.PostFormVarPrefix, jm.PostFormVarPrefix)
	assert.Len(t, jm.JTI.Get(), uuidLen)

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

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

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

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