github.com/dbernstein1/tyk@v2.9.0-beta9-dl-apic+incompatible/signature_validator/hash_test.go (about)

     1  package signature_validator
     2  
     3  import (
     4  	"encoding/hex"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  const (
    10  	token        = "5bcef48a3f03d311ff27d156630baf849e3b438b8a48fec99239d5c9"
    11  	sharedSecret = "foobar"
    12  	now          = 1546259837
    13  )
    14  
    15  func TestMasherySha256Sum_Hash(t *testing.T) {
    16  	expected := "fce2e80253cd438b666341176f34bde499116b63719e2482dae6965518ffd316"
    17  
    18  	hasher := MasherySha256Sum{}
    19  	hashed := hex.EncodeToString(hasher.Hash(token, sharedSecret, now))
    20  
    21  	if hashed != expected {
    22  		t.Fatalf("expected %s, got %s", expected, hashed)
    23  	}
    24  }
    25  
    26  func BenchmarkMasherySha256Sum_Hash(b *testing.B) {
    27  
    28  	b.ReportAllocs()
    29  
    30  	for n := 0; n < b.N; n++ {
    31  		hasher := MasherySha256Sum{}
    32  		hasher.Hash(token, sharedSecret, time.Now().Unix())
    33  	}
    34  }