Skip to content

Commit

Permalink
alts: Added peer attributes accessor for alts context and updated tes…
Browse files Browse the repository at this point in the history
…t method (#3675)
  • Loading branch information
d-reidenbach authored Jun 17, 2020
1 parent dfc058c commit 9a46550
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions credentials/alts/internal/authinfo/authinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func newAuthInfo(result *altspb.HandshakerResult) *altsAuthInfo {
PeerServiceAccount: result.GetPeerIdentity().GetServiceAccount(),
LocalServiceAccount: result.GetLocalIdentity().GetServiceAccount(),
PeerRpcVersions: result.GetPeerRpcVersions(),
PeerAttributes: result.GetPeerIdentity().GetAttributes(),
},
CommonAuthInfo: credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity},
}
Expand Down Expand Up @@ -87,3 +88,8 @@ func (s *altsAuthInfo) LocalServiceAccount() string {
func (s *altsAuthInfo) PeerRPCVersions() *altspb.RpcProtocolVersions {
return s.p.GetPeerRpcVersions()
}

// PeerAttributes returns the context's peer attributes.
func (s *altsAuthInfo) PeerAttributes() map[string]string {
return s.p.GetPeerAttributes()
}
25 changes: 19 additions & 6 deletions credentials/alts/internal/authinfo/authinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ func Test(t *testing.T) {
}

const (
testAppProtocol = "my_app"
testRecordProtocol = "very_secure_protocol"
testPeerAccount = "peer_service_account"
testLocalAccount = "local_service_account"
testPeerHostname = "peer_hostname"
testLocalHostname = "local_hostname"
testAppProtocol = "my_app"
testRecordProtocol = "very_secure_protocol"
testPeerAccount = "peer_service_account"
testLocalAccount = "local_service_account"
testPeerHostname = "peer_hostname"
testLocalHostname = "local_hostname"
testLocalPeerAttributeKey = "peer"
testLocalPeerAttributeValue = "attributes"
)

func (s) TestALTSAuthInfo(t *testing.T) {
testPeerAttributes := make(map[string]string)
testPeerAttributes[testLocalPeerAttributeKey] = testLocalPeerAttributeValue
for _, tc := range []struct {
result *altspb.HandshakerResult
outAppProtocol string
Expand All @@ -52,6 +56,7 @@ func (s) TestALTSAuthInfo(t *testing.T) {
outPeerAccount string
outLocalAccount string
outPeerRPCVersions *altspb.RpcProtocolVersions
outPeerAttributes map[string]string
}{
{
&altspb.HandshakerResult{
Expand All @@ -61,6 +66,7 @@ func (s) TestALTSAuthInfo(t *testing.T) {
IdentityOneof: &altspb.Identity_ServiceAccount{
ServiceAccount: testPeerAccount,
},
Attributes: testPeerAttributes,
},
LocalIdentity: &altspb.Identity{
IdentityOneof: &altspb.Identity_ServiceAccount{
Expand All @@ -74,6 +80,7 @@ func (s) TestALTSAuthInfo(t *testing.T) {
testPeerAccount,
testLocalAccount,
nil,
testPeerAttributes,
},
{
&altspb.HandshakerResult{
Expand All @@ -83,6 +90,7 @@ func (s) TestALTSAuthInfo(t *testing.T) {
IdentityOneof: &altspb.Identity_Hostname{
Hostname: testPeerHostname,
},
Attributes: testPeerAttributes,
},
LocalIdentity: &altspb.Identity{
IdentityOneof: &altspb.Identity_Hostname{
Expand Down Expand Up @@ -115,6 +123,7 @@ func (s) TestALTSAuthInfo(t *testing.T) {
Minor: 11,
},
},
testPeerAttributes,
},
} {
authInfo := newAuthInfo(tc.result)
Expand All @@ -139,5 +148,9 @@ func (s) TestALTSAuthInfo(t *testing.T) {
if got, want := authInfo.PeerRPCVersions(), tc.outPeerRPCVersions; !reflect.DeepEqual(got, want) {
t.Errorf("authinfo.PeerRpcVersions()=%v, want %v", got, want)
}
if got, want := authInfo.PeerAttributes(), tc.outPeerAttributes; !reflect.DeepEqual(got, want) {
t.Errorf("authinfo.PeerAttributes()=%v, want %v", got, want)
}

}
}

0 comments on commit 9a46550

Please sign in to comment.