1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: class Horde_Kolab_Test_Filter
29: {
30: 31: 32: 33: 34: 35: 36: 37: 38:
39: public function runGiven(&$world, $action, $arguments)
40: {
41: switch($action) {
42: case 'a set of Kolab test servers':
43: $world['servers'] = array();
44: $world['servers']['server'] = $this->prepareEmptyKolabServer();
45: $world['servers']['freebusy'] = $this->prepareEmptyKolabServer();
46: break;
47: case 'a set of test accounts':
48: foreach ($world['servers'] as $server) {
49: $this->prepareUsers($server['server']);
50: }
51: case 'a set of events where the test resource is busy':
52: foreach ($world['servers'] as $server) {
53: $this->prepareUsers($server);
54: }
55: default:
56: return parent::runGiven($world, $action, $arguments);
57: }
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67: 68:
69: public function runWhen(&$world, $action, $arguments)
70: {
71: switch($action) {
72: case 'inviting the resource':
73: default:
74: return parent::runWhen($world, $action, $arguments);
75: }
76: }
77:
78: 79: 80: 81: 82: 83: 84: 85: 86:
87: public function runThen(&$world, $action, $arguments)
88: {
89: switch($action) {
90: case 'the invitation is being rejected':
91: case 'the invitation is being accepted':
92: case 'the resource contains the event':
93: case 'the resource is busy during':
94: case 'the response contains':
95: default:
96: return parent::runThen($world, $action, $arguments);
97: }
98: }
99:
100: 101: 102: 103: 104: 105: 106:
107: public function prepareUsers(&$server)
108: {
109: parent::prepareUsers(&$server);
110: $result = $server->add($this->provideFilterUserOne());
111: $this->assertNoError($result);
112: $result = $server->add($this->provideFilterUserTwo());
113: $this->assertNoError($result);
114: $result = $server->add($this->provideFilterUserThree());
115: $this->assertNoError($result);
116: $result = $server->add($this->provideFilterCalendarUser());
117: $this->assertNoError($result);
118: }
119:
120: 121: 122: 123: 124:
125: public function prepareConfiguration()
126: {
127: $fh = fopen(HORDE_BASE . '/config/conf.php', 'w');
128: $data = <<<EOD
129: \$conf['use_ssl'] = 2;
130: \$conf['server']['name'] = \$_SERVER['SERVER_NAME'];
131: \$conf['server']['port'] = \$_SERVER['SERVER_PORT'];
132: \$conf['debug_level'] = E_ALL;
133: \$conf['umask'] = 077;
134: \$conf['compress_pages'] = true;
135: \$conf['menu']['always'] = false;
136: \$conf['portal']['fixed_blocks'] = array();
137: \$conf['imsp']['enabled'] = false;
138:
139: /** Additional config variables required for a clean Horde configuration */
140: \$conf['session']['use_only_cookies'] = false;
141: \$conf['session']['timeout'] = 0;
142: \$conf['cookie']['path'] = '/';
143: \$conf['cookie']['domain'] = \$_SERVER['SERVER_NAME'];
144: \$conf['use_ssl'] = false;
145: \$conf['session']['cache_limiter'] = 'nocache';
146: \$conf['session']['name'] = 'Horde';
147: \$conf['log']['enabled'] = false;
148: \$conf['prefs']['driver'] = 'session';
149: \$conf['auth']['driver'] = 'kolab';
150: \$conf['share']['driver'] = 'kolab';
151: \$conf['debug_level'] = E_ALL;
152:
153: /** Make the share driver happy */
154: \$conf['kolab']['enabled'] = true;
155:
156: /** Ensure we still use the LDAP test driver */
157: \$conf['kolab']['server']['driver'] = 'test';
158:
159: /** Ensure that we do not trigger on folder update */
160: \$conf['kolab']['no_triggering'] = true;
161:
162: /** Storage location for the free/busy system */
163: \$conf['fb']['cache_dir'] = '/tmp';
164: \$conf['kolab']['freebusy']['server'] = 'https://fb.example.org/freebusy';
165:
166: /** Setup the virtual file system for Kolab */
167: \$conf['vfs']['params']['all_folders'] = true;
168: \$conf['vfs']['type'] = 'kolab';
169:
170: \$conf['kolab']['imap']['server'] = 'localhost';
171: \$conf['kolab']['imap']['port'] = 0;
172: \$conf['kolab']['imap']['allow_special_users'] = true;
173: \$conf['kolab']['filter']['reject_forged_from_header'] = false;
174: \$conf['kolab']['filter']['email_domain'] = 'example.org';
175: \$conf['kolab']['filter']['privileged_networks'] = '127.0.0.1,192.168.0.0/16';
176: \$conf['kolab']['filter']['verify_from_header'] = true;
177: \$conf['kolab']['filter']['calendar_id'] = 'calendar';
178: \$conf['kolab']['filter']['calendar_pass'] = 'calendar';
179: \$conf['kolab']['filter']['lmtp_host'] = 'imap.example.org';
180: \$conf['kolab']['filter']['simple_locks'] = true;
181: \$conf['kolab']['filter']['simple_locks_timeout'] = 3;
182:
183: \$conf['kolab']['filter']['itipreply']['driver'] = 'echo';
184: \$conf['kolab']['filter']['itipreply']['params']['host'] = 'localhsot';
185: \$conf['kolab']['filter']['itipreply']['params']['port'] = 25;
186:
187: \$conf['freebusy']['driver'] = 'Mock';
188: EOD;
189: fwrite($fh, "<?php\n" . $data);
190: fclose($fh);
191: }
192:
193: 194: 195: 196: 197:
198: public function provideFilterUserOne()
199: {
200: return array(
201: 'type' => 'Horde_Kolab_Server_Object_Kolab_User',
202: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_GIVENNAME => 'Me',
203: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SN => 'Me',
204: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_MAIL => 'me@example.org',
205: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SID => 'me',
206: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_USERPASSWORD => 'me',
207: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_HOMESERVER => 'home.example.org',
208: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_IMAPHOST => 'imap.example.org',
209: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FREEBUSYHOST => 'https://fb.example.org/freebusy',
210: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_IPOLICY => array('ACT_REJECT_IF_CONFLICTS'),
211: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_ALIAS => array('me.me@example.org', 'MEME@example.org'),
212: );
213: }
214:
215: 216: 217: 218: 219:
220: public function provideFilterUserTwo()
221: {
222: return array(
223: 'type' => 'Horde_Kolab_Server_Object_Kolab_User',
224: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_GIVENNAME => 'You',
225: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SN => 'You',
226: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_MAIL => 'you@example.org',
227: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SID => 'you',
228: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_USERPASSWORD => 'you',
229: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_HOMESERVER => 'home.example.org',
230: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_IMAPHOST => 'home.example.org',
231: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FREEBUSYHOST => 'https://fb.example.org/freebusy',
232: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_ALIAS => array('you.you@example.org'),
233: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_DELEGATE => array('wrobel@example.org'),
234: );
235: }
236:
237: 238: 239: 240: 241:
242: public function provideFilterUserThree()
243: {
244: return array(
245: 'type' => 'Horde_Kolab_Server_Object_Kolab_User',
246: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_GIVENNAME => 'Else',
247: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SN => 'Else',
248: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_MAIL => 'else@example.org',
249: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SID => 'else',
250: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_USERPASSWORD => 'you',
251: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_HOMESERVER => 'imap.example.org',
252: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_IMAPHOST => 'imap.example.org',
253: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FREEBUSYHOST => 'https://fb.example.org/freebusy',
254: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_DELEGATE => array('me@example.org'),
255: );
256: }
257:
258: 259: 260: 261: 262:
263: public function provideFilterCalendarUser()
264: {
265: return array(
266: 'type' => 'Horde_Kolab_Server_Object_Kolab_User',
267: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_CN => 'calendar',
268: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_GIVENNAME => '',
269: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SN => 'calendar',
270: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_MAIL => 'calendar@example.org',
271: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_SID => 'calendar@home.example.com',
272: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_USERPASSWORD => 'calendar',
273: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_HOMESERVER => 'home.example.org',
274: Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_IMAPHOST => 'imap.example.org',
275: );
276: }
277:
278: public function sendFixture($infile, $outfile, $user, $client, $from, $to,
279: $host, $params = array())
280: {
281: $_SERVER['argv'] = array($_SERVER['argv'][0],
282: '--sender=' . $from,
283: '--recipient=' . $to,
284: '--user=' . $user,
285: '--host=' . $host,
286: '--client=' . $client);
287:
288: $in = file_get_contents($infile, 'r');
289:
290: $tmpfile = Horde_Util::getTempFile('KolabFilterTest');
291: $tmpfh = @fopen($tmpfile, 'w');
292: if (empty($params['unmodified_content'])) {
293: @fwrite($tmpfh, sprintf($in, $from, $to));
294: } else {
295: @fwrite($tmpfh, $in);
296: }
297: @fclose($tmpfh);
298:
299: $inh = @fopen($tmpfile, 'r');
300:
301:
302: if (empty($params['incoming'])) {
303: require_once 'Horde/Kolab/Filter/Content.php';
304: $parser = new Horde_Kolab_Filter_Content();
305: } else {
306: require_once 'Horde/Kolab/Filter/Incoming.php';
307: $parser = new Horde_Kolab_Filter_Incoming();
308: }
309:
310: ob_start();
311:
312:
313: $result = $parser->parse($inh, 'echo');
314: if (empty($params['error'])) {
315: $this->assertNoError($result);
316: $this->assertTrue(empty($result));
317:
318: $output = ob_get_contents();
319: ob_end_clean();
320:
321: $out = file_get_contents($outfile);
322: $replace = array(
323: '/^Received:.*$/m' => '',
324: '/^Date:.*$/m' => '',
325: '/DTSTAMP:.*$/m' => '',
326: '/^--+=.*$/m' => '----',
327: '/^Message-ID.*$/m' => '----',
328: '/boundary=.*$/m' => '----',
329: '/\s/' => '',
330: );
331: foreach ($replace as $pattern => $replacement) {
332: $output = preg_replace($pattern, $replacement, $output);
333: $out = preg_replace($pattern, $replacement, $out);
334: }
335:
336: if (empty($params['unmodified_content'])) {
337: $this->assertEquals(sprintf($out, $from, $to), $output);
338: } else {
339: $this->assertEquals($out, $output);
340: }
341: } else {
342: $this->assertError($result, $params['error']);
343: }
344:
345: }
346: }
347: