Commit Graph

11 Commits

Author SHA1 Message Date
Sean McGinnis 215217ea8b
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: Idc319f3f8a3ddd57cba91e4cefc66dbb18d5cc22
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-18 11:53:42 -05:00
Leehom Li (feli5) 82707e15a5 Make sure audit middleware use own context
Keystone audit middleware requires to iterate req.context as dict,
but Glance requires to access req.context.read_only.
When glance enabled audit, they are conflict with each other.
This patch fix this issue by store audit context in
req.environ['audit.context']

Change-Id: Ib9a62a4cd0b7b9ffb9fa2d6440e8072d45ee0fee
Closes-Bug: #1809101
Signed-off-by: Leehom Li <feli5@cisco.com>
2018-12-24 02:02:17 +00:00
Jamie Lennox b8024ff8c6 Return and use an app wherever possible
Audit middleware does a lot of faking up environments and calling
methods instead of just running the middleware. It's a whole bunch
easier to just run the middleware wherever possible.

This means we don't have to stub context from tests as these tests
actually pass through the wsgi layer correctly. Ideally we would do more
of this.

Change-Id: I95377f030b07ffae18698ecc3c82cc6aa1dddbc7
2016-09-30 05:45:25 +00:00
Jamie Lennox 6a5ef484f2 Refactor audit tests to use create_middleware
The auth_token tests have a good layout for using create_middleware and
create_simple_middleware that makes it easy for tests to create
middleware for testing as required rather than having a self.middleware
object that gets overriden a lot.

Extract this create_middleware into a base class and implement it in
audit so the patterns are similar.

Change-Id: I2f050eef1684c8046f94dc2b88b4c97a56ea9cd8
2016-09-30 05:45:18 +00:00
Jamie Lennox 23808e1bae Extract oslo_messaging specific audit tests
Extract the whole class of tests that deals with oslo.messaging
notifications. This matches what we did with logging notifications.

Convert the tests to using mock fixtures rather than mock decorator
directly.

Change-Id: I805be038c1e4e1d2fe16328c44cfa03d793b0136
2016-09-30 05:44:14 +00:00
Jamie Lennox 2892744d5b Use the mocking fixture in notifier tests
All the notifier tests end up mocking out the notifier object so lets
just do it once for all tests.

This also splits out the test that tries to use the logging notifier
because it's a different setup.

Change-Id: I159a2d34fe833b0bbac70c41d521bbe1dccbc09c
2016-09-30 01:43:37 -04:00
Jamie Lennox 3ee96f1cb7 Refactor API tests to not run middleware
The API tests don't really use the API, they just test the creation of
an event so focus them on that.

There are two tests that are in the API class that really do test
middleware so they are moved back.

Change-Id: I345fe4f4c2a0d8f98ba1ff10491802002d590fa6
2016-06-28 10:06:11 +10:00
Jamie Lennox 46f831e886 Refactor audit api tests into their own file
These tests can be refactored futher to not involve the middleware at
all.

Change-Id: I8bbf2530b183ff8b78983bae7232ade5b810cc66
2016-06-27 12:15:26 +10:00
Jamie Lennox 515a990dce Extract a common notifier pattern
Create a notifier pattern that abstracts the message notification. This
should make it easier to test.

Change-Id: Ifbe3be434c304f1d3d4d570d645937a72c3503c8
2016-06-27 12:15:26 +10:00
Jamie Lennox b49449ff0b Use createfile fixture in audit test
Use the createfile fixture from oslotest rather than mkstemp in audit
middleware testing.

Change-Id: I1ce557c1d81e344bdaa10af65daf89f64f6011f0
2016-06-24 14:18:31 +00:00
Jamie Lennox 9c67feedb6 Move audit into its own folder
This is the start of a cleanup of some of the audit middleware code.

The test changes are because this reorders the test execution order and
some of the global project tests were setting long lasting state.

Change-Id: I7a5576c1f497b9a43420f66c9e511cf6f280b62e
2016-06-24 13:47:47 +00:00