MCPcopy Index your code
hub / github.com/rilldata/rill / TestGenerateDeviceAndUserCodeCollision

Function TestGenerateDeviceAndUserCodeCollision

admin/auth_code_test.go:20–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18}
19
20func TestGenerateDeviceAndUserCodeCollision(t *testing.T) {
21 deviceCodeSet := make(map[string]bool)
22 userCodeSet := make(map[string]bool)
23
24 for i := 0; i < 10000; i++ {
25 authCode, err := generateDeviceAndUserCode()
26 if err != nil {
27 t.Error(err)
28 }
29 if len(authCode.DeviceCode) != 32 {
30 t.Errorf("device code length is incorrect; got %d, want 32", len(authCode.DeviceCode))
31 }
32 if len(authCode.UserCode) != 8 {
33 t.Errorf("user code length is incorrect; got %d, want 8", len(authCode.UserCode))
34 }
35 if deviceCodeSet[authCode.DeviceCode] {
36 t.Errorf("device code collision: %s", authCode.DeviceCode)
37 }
38 if userCodeSet[authCode.UserCode] {
39 t.Errorf("user code collision: %s", authCode.UserCode)
40 }
41 deviceCodeSet[authCode.DeviceCode] = true
42 userCodeSet[authCode.UserCode] = true
43 }
44}

Callers

nothing calls this directly

Calls 3

ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected