1
# -*- coding: utf-8 -*-
3
# Copyright 2008-2015 Canonical
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Affero General Public License as
7
# published by the Free Software Foundation, either version 3 of the
8
# License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Affero General Public License for more details.
15
# You should have received a copy of the GNU Affero General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
# For further info, check http://launchpad.net/filesync-server
20
"""Check the message validation step."""
24
from ubuntuone.storageprotocol import request
25
from ubuntuone.storage.server.testing.testcase import TestWithDatabase
28
def is_protocol_error(failure):
30
Returns whether the failure is a PROTOCOL_ERROR
32
return (failure.check(request.StorageProtocolProtocolError) or
33
failure.getErrorMessage() == 'PROTOCOL_ERROR'
34
or re.search(r'^\s*type: PROTOCOL_ERROR\s*$',
35
failure.getErrorMessage(),
39
def fail_check(client):
41
Returns a closure to be used as an errback that checks that the
42
failure is a PROTOCOL_ERROR, and passes the test if so.
46
Check the failure is a PROTOCOL_ERROR
48
if is_protocol_error(f):
49
return client.test_done('ok')
55
class TestValidation(TestWithDatabase):
56
"""Tests for message validation."""
58
def test_make_invalid_share(self):
60
Test validation for invalid MAKE_DIR works
66
d = client.dummy_authenticate("open sesame")
67
d.addCallbacks(lambda r: client.get_root(), client.test_fail)
69
lambda r: client.make_dir('invalid share', r, "hola"),
71
d.addCallbacks(client.test_fail, fail_check(client))
73
return self.callback_test(_worker)
75
def test_make_invalid_parent(self):
77
Test validation for invalid MAKE_DIR works
83
d = client.dummy_authenticate("open sesame")
84
d.addCallbacks(lambda r: client.get_root(), client.test_fail)
86
lambda r: client.make_dir('', 'invalid parent', "hola"),
88
d.addCallbacks(client.test_fail, fail_check(client))
90
return self.callback_test(_worker)
92
def test_move_invalid_new_parent_node(self):
94
Test we fail moves to invalid nodes
100
d = client.dummy_authenticate("open sesame")
101
d.addCallbacks(lambda r: client.get_root(), client.test_fail)
103
lambda r: client.make_file('', r, "hola"),
105
d.addCallbacks(lambda mk: client.move('', mk.new_id,
106
'invalid new parent node',
109
d.addCallbacks(client.test_fail, fail_check(client))
111
return self.callback_test(_worker)
113
def test_accept_share_invalid_share_id(self):
115
Test we fail accept_shares with invalid share_ids
121
d = client.dummy_authenticate("open sesame")
122
d.addCallbacks(lambda r: client.accept_share('invalid share id',
125
d.addCallbacks(client.test_fail, fail_check(client))
127
return self.callback_test(_worker)