(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func (s) TestClientAuthorizationCheck(t *testing.T) { |
| 103 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 104 | defer cancel() |
| 105 | altsAuthInfo := &fakeALTSAuthInfo{testServiceAccount1} |
| 106 | p := &peer.Peer{ |
| 107 | AuthInfo: altsAuthInfo, |
| 108 | } |
| 109 | for _, tc := range []struct { |
| 110 | desc string |
| 111 | ctx context.Context |
| 112 | expectedServiceAccounts []string |
| 113 | success bool |
| 114 | code codes.Code |
| 115 | }{ |
| 116 | { |
| 117 | "working case", |
| 118 | peer.NewContext(ctx, p), |
| 119 | []string{testServiceAccount1, testServiceAccount2}, |
| 120 | true, |
| 121 | codes.OK, // err is nil, code is OK. |
| 122 | }, |
| 123 | { |
| 124 | "working case (case ignored)", |
| 125 | peer.NewContext(ctx, p), |
| 126 | []string{strings.ToUpper(testServiceAccount1), testServiceAccount2}, |
| 127 | true, |
| 128 | codes.OK, // err is nil, code is OK. |
| 129 | }, |
| 130 | { |
| 131 | "context does not have AuthInfo", |
| 132 | ctx, |
| 133 | []string{testServiceAccount1, testServiceAccount2}, |
| 134 | false, |
| 135 | codes.PermissionDenied, |
| 136 | }, |
| 137 | { |
| 138 | "unauthorized client", |
| 139 | peer.NewContext(ctx, p), |
| 140 | []string{testServiceAccount2, testServiceAccount3}, |
| 141 | false, |
| 142 | codes.PermissionDenied, |
| 143 | }, |
| 144 | } { |
| 145 | err := ClientAuthorizationCheck(tc.ctx, tc.expectedServiceAccounts) |
| 146 | if got, want := (err == nil), tc.success; got != want { |
| 147 | t.Errorf("%v: ClientAuthorizationCheck(_, %v)=(err=nil)=%v, want %v", tc.desc, tc.expectedServiceAccounts, got, want) |
| 148 | } |
| 149 | if got, want := status.Code(err), tc.code; got != want { |
| 150 | t.Errorf("%v: ClientAuthorizationCheck(_, %v).Code=%v, want %v", tc.desc, tc.expectedServiceAccounts, got, want) |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | type fakeALTSAuthInfo struct { |
| 156 | peerServiceAccount string |
nothing calls this directly
no test coverage detected