SHINDIG-1056 by lipeng, BasicRemoteContentTest doesn't depend on static private key...
[shindig.git] / php / test / common / BasicBlobCrypterTest.php
blobca4ca012cba30a867cb8bfd6d0e0d99d856cd7d4
1 <?php
2 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
21 /**
22 * BasicBlobCrypter test case.
24 class BasicBlobCrypterTest extends PHPUnit_Framework_TestCase {
26 /**
27 * @var BasicBlobCrypter
29 private $BasicBlobCrypter;
31 /**
32 * Prepares the environment before running a test.
34 protected function setUp() {
35 parent::setUp();
36 $this->BasicBlobCrypter = new BasicBlobCrypter();
39 /**
40 * Cleans up the environment after running a test.
42 protected function tearDown() {
43 $this->BasicBlobCrypter = null;
44 parent::tearDown();
47 /**
48 * Tests BasicBlobCrypter->__construct()
50 public function test__construct() {
51 $this->BasicBlobCrypter->__construct();
54 /**
55 * Tests BasicBlobCrypter->wrap()
57 public function testWrap() {
58 $test = array();
59 $test['o'] = 'o';
60 $test['v'] = 'v';
61 $test['a'] = 'a';
62 $test['d'] = 'd';
63 $test['u'] = 'u';
64 $test['m'] = 'm';
65 $wrapped = $this->BasicBlobCrypter->wrap($test);
66 $unwrapped = $this->BasicBlobCrypter->unwrap($wrapped, 3600);
67 $this->assertEquals($unwrapped['o'], 'o');
68 $this->assertEquals($unwrapped['v'], 'v');
69 $this->assertEquals($unwrapped['a'], 'a');
70 $this->assertEquals($unwrapped['d'], 'd');
71 $this->assertEquals($unwrapped['u'], 'u');
72 $this->assertEquals($unwrapped['m'], 'm');
75 /**
76 * Tests BasicBlobCrypter->wrap() exception
78 public function testWrapException() {
79 $this->setExpectedException('BlobExpiredException');
80 $test = array();
81 $test['o'] = 'o';
82 $test['v'] = 'v';
83 $test['a'] = 'a';
84 $test['d'] = 'd';
85 $test['u'] = 'u';
86 $test['m'] = 'm';
87 $wrapped = $this->BasicBlobCrypter->wrap($test);
88 /* there is a 180 seconds clock skew allowed, so this way we make sure it's expired */
89 $this->BasicBlobCrypter->unwrap($wrapped, - 4000);