-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariate_test.go
58 lines (48 loc) · 1.86 KB
/
variate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package sdk_test
import (
"testing"
"github.com/ctfer-io/chall-manager/sdk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_U_Variate(t *testing.T) {
t.Parallel()
assert := assert.New(t)
require := require.New(t)
const identity = "a0b1c2d3"
const base = "This is my super example flag!!!"
// Following test case asserts default variations, plus special
// character are not variated (still in default configuration).
variated := sdk.Variate(identity, base)
assert.NotEqual(base, variated)
assert.Equal(variated[len(variated)-3:], "!!!")
// Following test case asserts reproducibility of the variation.
// This should not be happening in production, but guarantees
// stability of operations if they does not complete for whatever
// reason and retry.
require.Equal(variated, sdk.Variate(identity, base))
// Following test case asserts default configuration if to not
// variated over special characters, mostly for readability.
assert.Equal(variated, sdk.Variate(identity, base,
sdk.WithLowercase(true),
sdk.WithUppercase(true),
sdk.WithNumeric(true),
sdk.WithSpecial(false),
))
// Following test case asserts custom (special=true) variations
// propagates to special characters.
variated = sdk.Variate(identity, base, sdk.WithSpecial(true))
assert.NotEqual(base, variated)
assert.NotEqual(variated[len(variated)-3:], "!!!")
// Following test case asserts non-pritable ascii extended character
// is not variated.
// For this purpose, we encourage one who require it to use another
// leet implementation.
nonAE := string([]byte{0x00})
variated = sdk.Variate(identity, nonAE)
assert.Equal(nonAE, variated)
// Following test cases asserts non-8-long identity can also work.
// This should not happen, but even if it does it should not crash.
sdk.Variate("0123", base)
sdk.Variate("0123456789abcdef", base)
}