| 1 | package tests |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/cretz/bine/tor" |
| 7 | ) |
| 8 | |
| 9 | func TestAuthenticateNull(t *testing.T) { |
| 10 | ctx := NewTestContext(t, &tor.StartConf{DisableCookieAuth: true, DisableEagerAuth: true}) |
| 11 | defer ctx.Close() |
| 12 | // Verify auth methods before auth |
| 13 | info, err := ctx.Control.ProtocolInfo() |
| 14 | ctx.Require.NoError(err) |
| 15 | ctx.Require.ElementsMatch([]string{"NULL"}, info.AuthMethods) |
| 16 | ctx.Require.NoError(ctx.Control.Authenticate("")) |
| 17 | } |
| 18 | |
| 19 | func TestAuthenticateSafeCookie(t *testing.T) { |
| 20 | ctx := NewTestContext(t, &tor.StartConf{DisableEagerAuth: true}) |
| 21 | defer ctx.Close() |
| 22 | // Verify auth methods before auth |
| 23 | info, err := ctx.Control.ProtocolInfo() |
| 24 | ctx.Require.NoError(err) |
| 25 | ctx.Require.ElementsMatch([]string{"COOKIE", "SAFECOOKIE"}, info.AuthMethods) |
| 26 | ctx.Require.NoError(ctx.Control.Authenticate("")) |
| 27 | } |
| 28 | |
| 29 | func TestAuthenticateHashedPassword(t *testing.T) { |
| 30 | // "testpass" - 16:5417AE717521511A609921392778FFA8518EC089BF2162A199241AEB4A |
| 31 | ctx := NewTestContext(t, &tor.StartConf{ |
| 32 | DisableCookieAuth: true, |
| 33 | DisableEagerAuth: true, |
| 34 | ExtraArgs: []string{"--HashedControlPassword", "16:5417AE717521511A609921392778FFA8518EC089BF2162A199241AEB4A"}, |
| 35 | }) |
| 36 | defer ctx.Close() |
| 37 | // Verify auth methods before auth |
| 38 | info, err := ctx.Control.ProtocolInfo() |
| 39 | ctx.Require.NoError(err) |
| 40 | ctx.Require.ElementsMatch([]string{"HASHEDPASSWORD"}, info.AuthMethods) |
| 41 | ctx.Require.NoError(ctx.Control.Authenticate("testpass")) |
| 42 | } |