(lis net.Listener)
| 143 | } |
| 144 | |
| 145 | func serverAndClientHandshake(lis net.Listener) (credentials.SecurityLevel, error) { |
| 146 | done := make(chan testServerHandleResult, 1) |
| 147 | const timeout = 5 * time.Second |
| 148 | timer := time.NewTimer(timeout) |
| 149 | defer timer.Stop() |
| 150 | go serverHandle(serverLocalHandshake, done, lis) |
| 151 | defer lis.Close() |
| 152 | clientAuthInfo, err := clientHandle(clientLocalHandshake, lis.Addr().Network(), lis.Addr().String()) |
| 153 | if err != nil { |
| 154 | return credentials.InvalidSecurityLevel, fmt.Errorf("Error at client-side: %v", err) |
| 155 | } |
| 156 | select { |
| 157 | case <-timer.C: |
| 158 | return credentials.InvalidSecurityLevel, fmt.Errorf("Test didn't finish in time") |
| 159 | case serverHandleResult := <-done: |
| 160 | if serverHandleResult.err != nil { |
| 161 | return credentials.InvalidSecurityLevel, fmt.Errorf("Error at server-side: %v", serverHandleResult.err) |
| 162 | } |
| 163 | clientSecLevel := getSecurityLevelFromAuthInfo(clientAuthInfo) |
| 164 | serverSecLevel := getSecurityLevelFromAuthInfo(serverHandleResult.authInfo) |
| 165 | |
| 166 | if clientSecLevel == credentials.InvalidSecurityLevel { |
| 167 | return credentials.InvalidSecurityLevel, fmt.Errorf("Error at client-side: client's AuthInfo does not implement GetCommonAuthInfo()") |
| 168 | } |
| 169 | if serverSecLevel == credentials.InvalidSecurityLevel { |
| 170 | return credentials.InvalidSecurityLevel, fmt.Errorf("Error at server-side: server's AuthInfo does not implement GetCommonAuthInfo()") |
| 171 | } |
| 172 | if clientSecLevel != serverSecLevel { |
| 173 | return credentials.InvalidSecurityLevel, fmt.Errorf("client's AuthInfo contains %s but server's AuthInfo contains %s", clientSecLevel.String(), serverSecLevel.String()) |
| 174 | } |
| 175 | return clientSecLevel, nil |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | func (s) TestServerAndClientHandshake(t *testing.T) { |
| 180 | testCases := []struct { |
no test coverage detected