MCPcopy Create free account
hub / github.com/imroc/req / TestAuthenticate

Function TestAuthenticate

internal/socks/socks_test.go:24–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestAuthenticate(t *testing.T) {
25 auth := &UsernamePassword{
26 Username: "imroc",
27 Password: "123456",
28 }
29 buf := bytes.NewBuffer([]byte{byte(0x01), byte(0x00)})
30 err := auth.Authenticate(context.Background(), buf, AuthMethodUsernamePassword)
31 tests.AssertNoError(t, err)
32 auth.Username = "this is a very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long name"
33 err = auth.Authenticate(context.Background(), buf, AuthMethodUsernamePassword)
34 tests.AssertErrorContains(t, err, "invalid")
35
36 auth.Username = "imroc"
37 buf = bytes.NewBuffer([]byte{byte(0x03), byte(0x00)})
38 err = auth.Authenticate(context.Background(), buf, AuthMethodUsernamePassword)
39 tests.AssertErrorContains(t, err, "invalid username/password version")
40
41 buf = bytes.NewBuffer([]byte{byte(0x01), byte(0x02)})
42 err = auth.Authenticate(context.Background(), buf, AuthMethodUsernamePassword)
43 tests.AssertErrorContains(t, err, "authentication failed")
44
45 err = auth.Authenticate(context.Background(), buf, AuthMethodNoAcceptableMethods)
46 tests.AssertErrorContains(t, err, "unsupported authentication method")
47
48}

Callers

nothing calls this directly

Calls 3

AuthenticateMethod · 0.95
AssertNoErrorFunction · 0.92
AssertErrorContainsFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…