Commit Graph

4000 Commits

Author SHA1 Message Date
Damian Johnson
8fd556572a Function and testing for cookie authentication
Adding a function for password authentication. This includes checks for the
file's existance and that the size is valid (for 4303).
2011-12-01 10:10:43 -08:00
Damian Johnson
2c91e342a5 Skipping get_pid_by_name test when doomed
The get_pid_by_name function fails when there's multiple instances of a process
with that name. As a result the integ test for the function fails if there's
extra tor instances running on the system.

Using pgrep to check for other instances and skip those tests if they'd be
doomed to failure.
2011-11-30 19:02:32 -08:00
Damian Johnson
7f760f8641 Function and testing for password authentication
Adding a function for password authentication. This included escaping quotes
but otherwise is trivial - most of the effort was refactoring the
authentication integ tests.
2011-11-29 10:02:24 -08:00
Damian Johnson
312423c9d0 Function and testing for null authentication
Function for authenticating to open connections and integration testing for it.
The tests both check the happy case and responses we get in a variety of
'authentication needed' scenarios.
2011-11-28 10:08:20 -08:00
Damian Johnson
c033f19b08 Using ControlSocket for integ tests
Replacing the send_message and recv_message calls via raw sockets with the
ControlSocket class. Neither of these integ tests are for testing those methods
and the higher level objects make the tests much more readable.
2011-11-28 09:39:14 -08:00
Damian Johnson
206e4de3ff Exercising the get_socket arg with integ testing
The get_socket (previously keep_alive) argument wasn't being exercised so
adding that to the test for fetching a protocolinfo response via the control
socket.
2011-11-28 07:00:45 -08:00
Damian Johnson
04975ff9d1 Splitting socket attribute from protocolinfo
Bundling the requesting socket with the protocolinfo response was kinda clunky.
I thought that it owuld make the api a little nicer, but in retrospect it's
just weird so going to a more conventional tuple response instead.
2011-11-28 06:56:38 -08:00
Damian Johnson
7bae33db31 Specialized subclasses for ControlSocket
Adding a ControlSocket subclass for control ports and control sockets. This
allows for a connect() method which we'll need when trying multiple connection
types since the socket becomes detached after a failed authentication attempt.
This is also gonna be a bit nicer for callers since it bundles the connection
information (the port/path we're using) with the socket.
2011-11-28 06:24:49 -08:00
Damian Johnson
ec5c082e57 Moving scratch control connection into a module
Later there will be a stem.control for the general controller code (ie, most of
what TorCtl encompasses on its surface). Moving the first draft at that out of
stem.connection, which it didn't really belong in anyway. Now none of the
modules except control contain untested, scrap code.
2011-11-26 10:23:48 -08:00
Damian Johnson
5b505ec579 Fixing relative cookie expansion test
A couple protocolinfo tests filtered system calls so that pid lookups by
process name would fall and we'd fall back on looking it up by the control port
or socket file (to exercise alternative code paths). However, I'd forgotten
that this would also filter out the get_cwd lookup calls, causing those tests
to fail.

The relative cookie expansion by socket file wasn't being exercised at all
because I didn't have a integ test configuration where we had both a control
socket and authentication cookie. I've added this test now and fixed this issue
with the socket test too.
2011-11-26 10:10:21 -08:00
Damian Johnson
fd90d6c500 Using space or newline div when logging
When logging a multi-line message using a newline divider with the "Sending:"
or "Receiving:" prefix, otherwise using a space (minor bug had the space always
included previously).
2011-11-25 22:55:57 -08:00
Damian Johnson
8f8257d4dd Only respecting open default when undefined
When no target is defined we should have a test.runner.TorConnection.OPEN
default for integraiton tests. However, if we have an alternative connection
target then this should be overwritten.
2011-11-25 22:42:35 -08:00
Damian Johnson
e313bb35c8 Replacing protocolinfo lookups with ControlSocket
Replacing raw socket use in the protocolinfo lookup functions with the
ControlSocket class, and attaching it to the responses instead.
2011-11-25 22:36:57 -08:00
Damian Johnson
62ecde1d44 Refactoring version functions into module
Moving the last of the types.py contents and a related function from process.py
into a module specifically for handling tor versions and requirements (the
later part will grow as the library matures).
2011-11-25 22:21:07 -08:00
Damian Johnson
9a06ff17de Moving control message handling into stem.socket
Making a module for all low-level message handling with control sockets (ie,
pretty much all of the library work done so far). This includes most of the
code from the grab bag 'stem.types' module and the addition of a ControlSocket
class. The socket wrapper should greatly simplify upcoming parts of the
library.
2011-11-25 17:54:59 -08:00
Damian Johnson
e3d4311962 Showing shorter single-line controller messages
When controller messages are on a single line logging them that way too, making
the output a little more readable. I should probably file send/recv at a trace
runlevel or with a separate logger...
2011-11-23 10:05:15 -08:00
Damian Johnson
8dc796d142 Function for writting to control sockets
Writing directly to the socket file isn't hard (it's just a write and flush).
However, this is nicer since it wrap the control formatting, logging, and
exception quirks. Functions still need unit tests and I might just wrap the
socket object completely...
2011-11-23 09:55:16 -08:00
Damian Johnson
f98822f01e Defaulting open connection integ target
All connection targets were being defaulted to false, causing plain "run_tests
--integ" runs to be no-ops. Hacking in the default values. I should probably
use the more conventional dict/update pattern later.
2011-11-23 09:23:42 -08:00
Damian Johnson
1c2337a71f Nicer logging when receiving controller data
Changing the logged controller messages a bit. This is a bit less faithful to
the raw controller response but it's more readable.
2011-11-23 06:47:11 -08:00
Damian Johnson
b3afd554ba Better exercising cookie expansion in integ tests
The get_protocolinfo_by_* functions weren't exercising cookie path expansion by
port or socket file because lookups by process name would succeed and bypass
this logic. Added a filter to the integ tests so we exercise both.

When running with both the 'RELATIVE' and 'CONN_COOKIE' targets this reveals a
bug with the stem.util.system.get_pid_by_port function that I'll address next.
The test using the socket file passes.
2011-11-22 10:13:39 -08:00
Damian Johnson
03d2e84894 Noting at the end of testing if it passed/failed
As testing output has gotten longer its become less clear at the end if all
tests passed or not. Adding a note at the end saying if they all passed and, if
there were failures, what they were.
2011-11-22 10:06:48 -08:00
Damian Johnson
9fb5221049 More selective options for running integ tests
Providing targets for all of the tor connection configurations so the user can
opt for any combination of targets. Previously you needed to run the
'CONNECTION' target which exercised them all and took around forty seconds to
run (kinda a pita if you just want to test cookie auth).
2011-11-22 09:53:30 -08:00
Damian Johnson
d3b8f0aed7 Integ target for running with a relative data dir
Having a relative path for our data directory can cause headaches since tor
then provides relative paths for the data it gives (for instance, for the
authentication cookie location). Adding an integration testing target to have a
relative data directory, to better exercise the path expansion code.
2011-11-21 10:13:10 -08:00
Damian Johnson
56c2ea8c33 Function to query PROTOCOLINFO via control socket
Same as before, implementation and integ sanity check for making a PROTOCOLINFO
query via a control socket. This has the common bits between it, the control
port function, and a bit of the PROTOCOLINFO response parsing delegated to
helper functions.
2011-11-21 09:37:37 -08:00
Damian Johnson
7f89ff58d2 Function to query PROTOCOLINFO via a control port
Implementation and integ testing to query a PROTOCOLINFO response via a control
port. Next is to do the same for control sockets.
2011-11-21 08:36:20 -08:00
Damian Johnson
e17bfdd0c4 Resetting system call mocking after test
The protocolinfo test mocked system calls but didn't reset the mock when it was
done. This didn't cause any errors but that was only luck (the system unit
tests probably ran afterward and cleared the mock when it was done). Oops, this
is gonna be an easy testing bug to introduce... :/
2011-11-21 07:51:00 -08:00
Damian Johnson
708e082fb7 Moving PROTOCOLINFO tests to be grouped by subject
All the PROTOCOLINFO related tests might as well be together. Shuffling them
around so all the tests can reside in a test/*/protocolinfo.py rather than have
separate protocolinfo_response.py, protocolinfo_query.py, etc.
2011-11-21 07:42:14 -08:00
Damian Johnson
07fd7f7d23 Expanding coverage of PROTOCOLINFO integ test
Providing the assertions for all connection configurations in the integ test.
2011-11-21 04:29:10 -08:00
Damian Johnson
22667eaa6a Unit test for comparing Version class with others
Had a pesky bug where comparison of Version instances with other classes would
raise an exception and had forgotten to add a unit test - fixing that.
2011-11-21 03:59:27 -08:00
Damian Johnson
3d14e1bd10 Running integ tests multiple connections methods
Adding a 'CONNECTION' target that, if set, will run integration tests with
multiple connection and authentication methods...
- no control connection
- control port with no auth
- control port with an authentication cookie
- control port with a password
- control port with both an authtication cookie and password
- control socket

This means running through the integ tests six times which currently results in
a runtime of arond fourty sectons, so this isn't the default.

The primary purpose for doing this is to exercise the PROTOCOLINFO parsing and
upcoming connecion methods with all of these tor configurations. The
ProtocolInfoResponse integ test doesn't yet actually test all of these - fixing
that is next.
2011-11-20 15:51:29 -08:00
Damian Johnson
e625026610 Adding a set method for config instances 2011-11-20 14:22:07 -08:00
Damian Johnson
da937730bb Using enum.__iter__ for values rather than keys
Enumeration keys are of very limited use. Iteration over an enumeration should
give the values instead so swapping values() and __iter__() to be keys() and
__iter__().
2011-11-20 14:20:13 -08:00
Damian Johnson
a34316c59e Runner startup argument for tor connection type
Integration tests are about to get an option for exercising multiple connection
methods, so adding a runner initialization argument for starting with a torrc
for all of the connection methods that we care about. This also includes a
minor fix where we'd get a stacktrace when the torrc had an empty line.
2011-11-20 00:55:15 -08:00
Damian Johnson
7b302e2eac Integration test for general PROTOCOLINFO parsing
Integ test for parsing a PROTOCOLINFO reply from our general integraion test
instance. We'll need a separate target for testing multiple connection methods
(password auth, cookie auth, and control socket).

This also includes a fix for the Version class (equality checks with
non-Version instaces would raise an exception - didn't expect __cmp__ to be
used for that...).
2011-11-19 23:58:26 -08:00
Damian Johnson
2c4686adce Unit test for relative cookie expansion
Now that we have system call mocking we can have a unit test for expanding
relative cookie paths. It kinda bugged me that testing wasn't complaining when
we had a system api change. :)
2011-11-19 23:16:26 -08:00
Damian Johnson
5847301f60 Using new system api for protocolinfo queries
The protocolinfo uses system utils for expansion of relative cookie paths.
Making it use the new api (the breakup of the get_pid_by_* functions was
largely for this class).
2011-11-19 22:25:21 -08:00
Damian Johnson
314804dfce Dropping log inference from conf util
The config's get method inference for logging runlevels no longer makes sense
since the log util has been removed. Dropping this inference entirely rather
than trying to make it work with logging - those config options have always
been unused anyway.
2011-11-19 22:05:52 -08:00
Damian Johnson
ff5895f821 Color for testing output
Applying color to the unittest output: green for success, blue for skips, red
for failure. Bit easier on the eyes and makes issues easier to spot (at least
on my terminal).
2011-11-19 22:05:11 -08:00
Damian Johnson
70ab8ff1c2 System test bugs caught by pylint
Couple copy-paste bugs with the system integ tests.
2011-11-19 14:18:13 -08:00
Damian Johnson
f6560b1210 Rewrite and testing for system utilities
Spent most of this week improving the implementation, api, documentation, and
most importantly testing for the system functions. They now have almost
complete code coverage by both unit and integ tests. Besides the obvious, this
will help cross-platform compatability in the future since I'll have a sampling
of input for platforms I don't have.

Generated real output for all commands except sockstat (I only have access to
linux and mac, not free/openbsd). I'll probably contact Fabian for help with
this one.
2011-11-18 23:23:28 -08:00
Damian Johnson
dbe041ac1b Header documentation for the proc and system utils 2011-11-13 16:26:40 -08:00
Damian Johnson
382bc5627b Basic integ test for stem.util.conf
Adding an integ test for the example given by the conf utility. There's a whole
lot more that could be tested in that class (especially parsing and type
inferences) but this doesn't seem too worth while so just adding this basic
test for now. I might expand it later.
2011-11-13 16:13:33 -08:00
Damian Johnson
b34f8990b6 Shuffling integ tests to match unit tests
Unit tests are nicely categorized under their respective modules, so reordering
integration tests to match.
2011-11-13 15:28:19 -08:00
Damian Johnson
d30e229c32 Unit tests for enum 2011-11-13 15:02:47 -08:00
Damian Johnson
db7635abc7 Revising enum docs and methods
Minor changes including...
- standard header documentation
- replacing the keys() method with making enums iterable (functionally the
  same, but a little nicer for callers)
- dropping the alternative LEnum - I've never used it
2011-11-13 14:38:56 -08:00
Damian Johnson
f9aeefb280 Rearranging conf util to improve usability
Adding the standard configuration header (... sooo helpful) and moving the rest
of the util's contents around to be more intuitive.
2011-11-13 14:01:55 -08:00
Damian Johnson
fc562144fd Including stem prefix for paths in stem comments 2011-11-13 13:43:59 -08:00
Damian Johnson
2b797d0ba9 Unit tests for PROTOCOLINFO responses 2011-11-13 13:15:49 -08:00
Damian Johnson
5756f9940f Parsing and class for PROTOCOLINFO responses
Finally have enough plumbing in place to write the parsing for the PROTOCOLINFO
queries. I'm pretty happy with how it turned out - next is testing for the
class, then moving on to functions for issuing the PROTOCOLINFO queries.
2011-11-13 02:19:26 -08:00
Damian Johnson
5d200b1cdb Avoid adding duplicate null logging handlers
Checking if logging already has a handler before adding a NullHandler, to
avoid having _every_ import trigger an extra no-op handler.
2011-11-12 16:19:34 -08:00