forked from fluxcd/source-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The underlying SSH connections are kept open and are reused across several SSH sessions. This is due to upstream issues in which concurrent/parallel SSH connections may lead to instability. golang/go#51926 golang/go#27140 Signed-off-by: Paulo Gomes <[email protected]>
- Loading branch information
Paulo Gomes
committed
Mar 25, 2022
1 parent
58d6828
commit 08c3490
Showing
2 changed files
with
220 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Copyright 2022 The Flux authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package managed | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCacheKey(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
remoteAddress1 string | ||
user1 string | ||
passphrase1 string | ||
pubKey1 []byte | ||
remoteAddress2 string | ||
user2 string | ||
passphrase2 string | ||
pubKey2 []byte | ||
expectMatch bool | ||
}{ | ||
{ | ||
description: "same remote addresses with no config", | ||
remoteAddress1: "1.1.1.1", | ||
remoteAddress2: "1.1.1.1", | ||
expectMatch: true, | ||
}, | ||
{ | ||
description: "same remote addresses with different config", | ||
remoteAddress1: "1.1.1.1", | ||
user1: "joe", | ||
remoteAddress2: "1.1.1.1", | ||
user2: "another-joe", | ||
expectMatch: false, | ||
}, | ||
{ | ||
description: "different remote addresses with no config", | ||
remoteAddress1: "8.8.8.8", | ||
remoteAddress2: "1.1.1.1", | ||
expectMatch: false, | ||
}, | ||
{ | ||
description: "different remote addresses with same config", | ||
remoteAddress1: "8.8.8.8", | ||
user1: "legit", | ||
remoteAddress2: "1.1.1.1", | ||
user2: "legit", | ||
expectMatch: false, | ||
}, | ||
{ | ||
description: "same remote addresses with same pubkey signers", | ||
remoteAddress1: "1.1.1.1", | ||
user1: "same-jane", | ||
pubKey1: []byte{255, 123, 0}, | ||
remoteAddress2: "1.1.1.1", | ||
user2: "same-jane", | ||
pubKey2: []byte{255, 123, 0}, | ||
expectMatch: true, | ||
}, | ||
{ | ||
description: "same remote addresses with different pubkey signers", | ||
remoteAddress1: "1.1.1.1", | ||
user1: "same-jane", | ||
pubKey1: []byte{255, 123, 0}, | ||
remoteAddress2: "1.1.1.1", | ||
user2: "same-jane", | ||
pubKey2: []byte{0, 123, 0}, | ||
expectMatch: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
cacheKey1 := cacheKey(tt.remoteAddress1, tt.user1, tt.passphrase1, tt.pubKey1) | ||
cacheKey2 := cacheKey(tt.remoteAddress2, tt.user2, tt.passphrase2, tt.pubKey2) | ||
|
||
if tt.expectMatch && cacheKey1 != cacheKey2 { | ||
t.Errorf("%s: cache keys '%s' and '%s' should match", tt.description, cacheKey1, cacheKey2) | ||
} | ||
|
||
if !tt.expectMatch && cacheKey1 == cacheKey2 { | ||
t.Errorf("%s: cache keys '%s' and '%s' should not match", tt.description, cacheKey1, cacheKey2) | ||
} | ||
} | ||
} |