-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replacing crc32 by sha256 hash sum and making sure it doesn't re…
…turn a negative value
- Loading branch information
1 parent
d549c37
commit d0e76cf
Showing
2 changed files
with
88 additions
and
7 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,70 @@ | ||
package fronted | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGenerateSNI(t *testing.T) { | ||
emptyMasquerade := new(Masquerade) | ||
var tests = []struct { | ||
name string | ||
assert func(t *testing.T, actual string) | ||
givenConfig *SNIConfig | ||
givenMasquerade *Masquerade | ||
}{ | ||
{ | ||
name: "should return a empty string when given SNI config is nil", | ||
givenConfig: nil, | ||
givenMasquerade: emptyMasquerade, | ||
assert: func(t *testing.T, actual string) { | ||
assert.Empty(t, actual) | ||
}, | ||
}, | ||
{ | ||
name: "should return a empty string when given SNI config is not nil and UseArbitrarySNIs is false", | ||
givenConfig: &SNIConfig{ | ||
UseArbitrarySNIs: false, | ||
}, | ||
givenMasquerade: emptyMasquerade, | ||
assert: func(t *testing.T, actual string) { | ||
assert.Empty(t, actual) | ||
}, | ||
}, | ||
{ | ||
name: "should return a empty SNI when the list of arbitrary SNIs is empty", | ||
givenConfig: &SNIConfig{ | ||
UseArbitrarySNIs: true, | ||
ArbitrarySNIs: []string{}, | ||
}, | ||
givenMasquerade: &Masquerade{ | ||
IpAddress: "1.1.1.1", | ||
Domain: "randomdomain.net", | ||
}, | ||
assert: func(t *testing.T, actual string) { | ||
assert.Empty(t, actual) | ||
}, | ||
}, | ||
{ | ||
name: "should return a SNI when given SNI config is not nil and UseArbitrarySNIs is true", | ||
givenConfig: &SNIConfig{ | ||
UseArbitrarySNIs: true, | ||
ArbitrarySNIs: []string{"sni1.com", "sni2.com"}, | ||
}, | ||
givenMasquerade: &Masquerade{ | ||
IpAddress: "1.1.1.1", | ||
Domain: "randomdomain.net", | ||
}, | ||
assert: func(t *testing.T, actual string) { | ||
assert.NotEmpty(t, actual) | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actual := generateSNI(tt.givenConfig, tt.givenMasquerade) | ||
tt.assert(t, actual) | ||
}) | ||
} | ||
} |