github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/plugin/local_verifier_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestLocalVerifier_VerifySignature(t *testing.T) {
    13  	tmpDir, err := ioutil.TempDir("", "q-")
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  	defer func() {
    18  		_ = os.RemoveAll(tmpDir)
    19  	}()
    20  	arbitraryPluginDefinition := &PluginDefinition{
    21  		Name:    "arbitrary-plugin",
    22  		Version: "1.0.0",
    23  		Config:  nil,
    24  	}
    25  	pubKeyFile := path.Join(tmpDir, "pubkey")
    26  	if err := ioutil.WriteFile(pubKeyFile, signerPubKey, 0644); err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	sigFile := path.Join(tmpDir, arbitraryPluginDefinition.SignatureFileName())
    30  	if err := ioutil.WriteFile(sigFile, validSignature, 0644); err != nil {
    31  		t.Fatal(err)
    32  	}
    33  
    34  	testObject, err := NewLocalVerifier(pubKeyFile, tmpDir)
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	assert.NoError(t, testObject.VerifySignature(arbitraryPluginDefinition, arbitraryChecksum))
    39  }