Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pfs_middleware: Stop hardcoding allowed PROXYFS methods in tests #285

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions pfs_middleware/tests/test_pfs_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from xml.etree import ElementTree

import pfs_middleware.middleware as mware
import pfs_middleware.bimodal_checker as bimodal_checker
from pfs_middleware import rpc
from pfs_middleware import bimodal_checker
from . import helpers


Expand Down Expand Up @@ -4716,6 +4717,9 @@ def test_best_possible_etag(self):


class TestProxyfsMethod(BaseMiddlewareTest):
allowed_rpc = next(method for method in rpc.allow_read_only
if method != 'Server.RpcIsAccountBimodal')

def test_non_swift_owner(self):
req = swob.Request.blank("/v1/AUTH_test", method='PROXYFS')
status, _, _ = self.call_pfs(req)
Expand Down Expand Up @@ -4751,7 +4755,7 @@ def expect_one_payload(body):
expect_one_payload(b'\n')
one_payload = json.dumps({
'jsonrpc': '2.0',
'method': 'Server.RpcPing',
'method': self.allowed_rpc,
'params': [{}],
})
expect_one_payload(one_payload + '\n' + one_payload)
Expand All @@ -4775,7 +4779,7 @@ def expect_parse_error(req_body):

expect_parse_error(json.dumps({
'jsonrpc': '1.0',
'method': 'Server.PingReq',
'method': self.allowed_rpc,
'params': [{}],
}).encode('ascii'))

Expand All @@ -4787,27 +4791,27 @@ def expect_parse_error(req_body):

expect_parse_error(json.dumps({
'jsonrpc': '2.0',
'method': 'Server.PingReq',
'method': self.allowed_rpc,
'params': [{}, {}],
}).encode('ascii'))
expect_parse_error(json.dumps({
'jsonrpc': '2.0',
'method': 'Server.PingReq',
'method': self.allowed_rpc,
'params': [],
}).encode('ascii'))
expect_parse_error(json.dumps({
'jsonrpc': '2.0',
'method': 'Server.PingReq',
'method': self.allowed_rpc,
'params': [[]],
}).encode('ascii'))
expect_parse_error(json.dumps({
'jsonrpc': '2.0',
'method': 'Server.PingReq',
'method': self.allowed_rpc,
'params': {},
}).encode('ascii'))

def test_success(self):
def mock_RpcGetAccount(params):
def mock_rpc(params):
self.assertEqual(params, {
"AccountName": "AUTH_test",
})
Expand All @@ -4830,15 +4834,14 @@ def mock_RpcGetAccount(params):
}],
}}

self.fake_rpc.register_handler(
"Server.RpcGetAccount", mock_RpcGetAccount)
self.fake_rpc.register_handler(self.allowed_rpc, mock_rpc)

req = swob.Request.blank(
"/v1/AUTH_test", method='PROXYFS',
headers={'Content-Type': 'application/json'},
environ={'swift_owner': True}, body=json.dumps({
'jsonrpc': '2.0',
'method': 'Server.RpcGetAccount',
'method': self.allowed_rpc,
'params': [{}],
}))
status, headers, body = self.call_pfs(req)
Expand Down Expand Up @@ -4867,22 +4870,21 @@ def mock_RpcGetAccount(params):
})

def test_error(self):
def mock_RpcGetAccount(params):
def mock_rpc(params):
self.assertEqual(params, {
"AccountName": "AUTH_test",
"some": "args",
})
return {"error": "errno 2"}

self.fake_rpc.register_handler(
"Server.RpcGetAccount", mock_RpcGetAccount)
self.fake_rpc.register_handler(self.allowed_rpc, mock_rpc)

req = swob.Request.blank(
"/v1/AUTH_test", method='PROXYFS',
headers={'Content-Type': 'application/json'},
environ={'swift_owner': True}, body=json.dumps({
'jsonrpc': '2.0',
'method': 'Server.RpcGetAccount',
'method': self.allowed_rpc,
'params': [{'some': 'args'}],
}))
status, headers, body = self.call_pfs(req)
Expand Down