Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Add more signature verification unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jvehent committed Jun 17, 2018
1 parent 6575e9a commit cf63270
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions verify_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package mar

import (
"crypto/x509"
"encoding/pem"
"log"
"testing"
)

func TestFirefoxKeys(t *testing.T) {
testMar := New()
testMar.AddContent([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), "/foo/bar", 0600)

// add the test rsa key to the list of firefox keys
publicKeyDer, err := x509.MarshalPKIXPublicKey(&rsa2048Key.PublicKey)
if err != nil {
t.Fatal(err)
}
publicKeyBlock := pem.Block{
Type: "PUBLIC KEY",
Headers: nil,
Bytes: publicKeyDer,
}
publicKeyPem := string(pem.EncodeToMemory(&publicKeyBlock))
FirefoxReleasePublicKeys["unit_test"] = publicKeyPem

testMar.PrepareSignature(rsa2048Key, rsa2048Key.Public())
testMar.FinalizeSignatures()

validKeys, isSigned, err := testMar.VerifyWithFirefoxKeys()
if err != nil {
log.Fatal(err)
}
if !isSigned {
t.Fatal("expected signed MAR file but didn't get one")
}
if len(validKeys) != 1 || validKeys[0] != "unit_test" {
t.Fatal("expected signature from 'unit_test' key but didn't get one")
}
}

0 comments on commit cf63270

Please sign in to comment.