...

Source file src/edge-infra.dev/pkg/edge/edgeencrypt/api_test.go

Documentation: edge-infra.dev/pkg/edge/edgeencrypt

     1  package edgeencrypt
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/google/uuid"
     7  )
     8  
     9  func TestEncryption(t *testing.T) {
    10  	e := &EncryptedData{
    11  		BannerEdgeID: "my-banner",
    12  		Channel:      "my-channel",
    13  		ChannelID:    uuid.NewString(),
    14  		KeyVersion:   "1",
    15  		Data:         []byte("encrypted data"),
    16  	}
    17  
    18  	encResp, err := e.ToEncryptionResponse()
    19  	if err != nil {
    20  		t.Fatalf("failed to marshal EncryptedData: %v", err)
    21  	}
    22  
    23  	// Note: encryption response data will be used as decryption request data
    24  
    25  	encryptedData, err := DecryptionRequest(encResp).ToEncryptedData()
    26  	if err != nil {
    27  		t.Fatalf("failed to unmarshal EncryptedData: %v", err)
    28  	}
    29  
    30  	if encryptedData.BannerEdgeID != e.BannerEdgeID {
    31  		t.Fatalf("expected BannerEdgeID %s, got %s", e.BannerEdgeID, encryptedData.BannerEdgeID)
    32  	}
    33  	if encryptedData.Channel != e.Channel {
    34  		t.Fatalf("expected Channel %s, got %s", e.Channel, encryptedData.Channel)
    35  	}
    36  	if encryptedData.ChannelID != e.ChannelID {
    37  		t.Fatalf("expected ChannelID %s, got %s", e.ChannelID, encryptedData.ChannelID)
    38  	}
    39  	if encryptedData.KeyVersion != e.KeyVersion {
    40  		t.Fatalf("expected KeyVersion %s, got %s", e.KeyVersion, encryptedData.KeyVersion)
    41  	}
    42  	if string(encryptedData.Data) != string(e.Data) {
    43  		t.Fatalf("expected Data %s, got %s", string(e.Data), string(encryptedData.Data))
    44  	}
    45  }
    46  

View as plain text