@@ -2130,6 +2130,77 @@ def test_450_property_reset(self):
2130
2130
self .assertIsNone (value )
2131
2131
self .app .save .assert_called_once_with ()
2132
2132
2133
+ def test_notes_get (self ):
2134
+ notes = "For Your Eyes Only"
2135
+ self .app .domains ["test-vm1" ].get_notes = unittest .mock .Mock ()
2136
+ self .app .domains ["test-vm1" ].get_notes .configure_mock (
2137
+ ** {"return_value" : notes }
2138
+ )
2139
+ value = self .call_mgmt_func (b"admin.vm.notes.Get" , b"test-vm1" )
2140
+ self .assertEqual (value , notes )
2141
+ self .app .domains ["test-vm1" ].get_notes .configure_mock (
2142
+ ** {"side_effect" : qubes .exc .QubesException ()}
2143
+ )
2144
+ with self .assertRaises (qubes .exc .QubesException ):
2145
+ self .call_mgmt_func (b"admin.vm.notes.Get" , b"test-vm1" )
2146
+ self .assertEqual (
2147
+ self .app .domains ["test-vm1" ].get_notes .mock_calls ,
2148
+ [unittest .mock .call (), unittest .mock .call ()],
2149
+ )
2150
+ self .assertFalse (self .app .save .called )
2151
+
2152
+ def test_notes_set (self ):
2153
+ self .app .domains ["test-vm1" ].set_notes = unittest .mock .Mock ()
2154
+
2155
+ # Acceptable note
2156
+ payload = b"For Your Eyes Only"
2157
+ self .call_mgmt_func (
2158
+ b"admin.vm.notes.Set" ,
2159
+ b"test-vm1" ,
2160
+ payload = payload ,
2161
+ )
2162
+ self .app .domains ["test-vm1" ].set_notes .assert_called_with (
2163
+ payload .decode ()
2164
+ )
2165
+
2166
+ # Note with new-line & tab characters
2167
+ payload = b"def python_example_function():\n \t pass"
2168
+ self .call_mgmt_func (
2169
+ b"admin.vm.notes.Set" ,
2170
+ b"test-vm1" ,
2171
+ payload = payload ,
2172
+ )
2173
+ self .app .domains ["test-vm1" ].set_notes .assert_called_with (
2174
+ payload .decode ()
2175
+ )
2176
+
2177
+ # Note with un-acceptable character (backspace, non-breaking space, ...)
2178
+ payload = "\b \xa0 \u200b \u200c \u200d " .encode ()
2179
+ self .call_mgmt_func (
2180
+ b"admin.vm.notes.Set" ,
2181
+ b"test-vm1" ,
2182
+ payload = payload ,
2183
+ )
2184
+ self .app .domains ["test-vm1" ].set_notes .assert_called_with ("_____" )
2185
+
2186
+ # Invalid UTF8 sequence
2187
+ with self .assertRaises (qubes .exc .ProtocolError ):
2188
+ payload = b"\xd8 "
2189
+ self .call_mgmt_func (
2190
+ b"admin.vm.notes.Set" ,
2191
+ b"test-vm1" ,
2192
+ payload = payload ,
2193
+ )
2194
+
2195
+ # Unacceptable oversized note
2196
+ with self .assertRaises (qubes .exc .ProtocolError ):
2197
+ payload = ("x" * 256001 ).encode ()
2198
+ self .call_mgmt_func (
2199
+ b"admin.vm.notes.Set" ,
2200
+ b"test-vm1" ,
2201
+ payload = payload ,
2202
+ )
2203
+
2133
2204
def device_list_testclass (self , vm , event ):
2134
2205
if vm is not self .vm :
2135
2206
return
0 commit comments