github.com/microsoft/moc@v0.17.1/pkg/redact/redact_test.go (about)

     1  // Copyright (c) Microsoft Corporation.
     2  // Licensed under the Apache v2.0 license.
     3  package redact
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/golang/protobuf/proto"
     9  	"github.com/microsoft/moc/rpc/cloudagent/security"
    10  	"github.com/microsoft/moc/rpc/common"
    11  )
    12  
    13  func Test_RedactedMessage(t *testing.T) {
    14  	id := security.Identity{
    15  		Name:          "testIdentity",
    16  		Id:            "123",
    17  		ResourceGroup: "testGroup",
    18  		Password:      "testPassword",
    19  		Token:         "testToken",
    20  		LocationName:  "testLocation",
    21  		Certificates: map[string]string{
    22  			"testKey1": "testVal1",
    23  			"testKey2": "testVal2",
    24  		},
    25  		TokenExpiry: 30,
    26  		ClientType:  common.ClientType_ADMIN,
    27  		Tags: &common.Tags{
    28  			Tags: []*common.Tag{
    29  				{
    30  					Key:   "testKey1",
    31  					Value: "testValue1",
    32  				},
    33  				{
    34  					Key:   "testKey2",
    35  					Value: "testValue2",
    36  				},
    37  			},
    38  		},
    39  	}
    40  	a := security.AuthenticationRequest{
    41  		Identity: &id,
    42  	}
    43  
    44  	expectedAuthenticationRequest := security.AuthenticationRequest{
    45  		Identity: &security.Identity{
    46  			Name:          "testIdentity",
    47  			Id:            "123",
    48  			ResourceGroup: "testGroup",
    49  			Password:      "** Redacted **",
    50  			Token:         "** Redacted **",
    51  			LocationName:  "testLocation",
    52  			TokenExpiry:   30,
    53  			ClientType:    common.ClientType_ADMIN,
    54  			Tags: &common.Tags{
    55  				Tags: []*common.Tag{
    56  					{
    57  						Key:   "testKey1",
    58  						Value: "testValue1",
    59  					},
    60  					{
    61  						Key:   "testKey2",
    62  						Value: "testValue2",
    63  					},
    64  				},
    65  			},
    66  		},
    67  	}
    68  	expect := &expectedAuthenticationRequest
    69  
    70  	msg := RedactedMessage(&a)
    71  
    72  	redacted := (msg).(*security.AuthenticationRequest)
    73  	if !proto.Equal(proto.Message(expect), redacted) {
    74  		t.Errorf("Redacted AuthenticationRequest: {%v} does not match expected: {%v}", redacted, expectedAuthenticationRequest)
    75  	}
    76  }