Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

47 řádky
860 B

  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package jws
  5. import (
  6. "crypto/rand"
  7. "crypto/rsa"
  8. "testing"
  9. )
  10. func TestSignAndVerify(t *testing.T) {
  11. header := &Header{
  12. Algorithm: "RS256",
  13. Typ: "JWT",
  14. }
  15. payload := &ClaimSet{
  16. Iss: "http://google.com/",
  17. Aud: "",
  18. Exp: 3610,
  19. Iat: 10,
  20. }
  21. privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. token, err := Encode(header, payload, privateKey)
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. err = Verify(token, &privateKey.PublicKey)
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. }
  34. func TestVerifyFailsOnMalformedClaim(t *testing.T) {
  35. err := Verify("abc.def", nil)
  36. if err == nil {
  37. t.Error("got no errors; want improperly formed JWT not to be verified")
  38. }
  39. }