| 1 |
/* |
| 2 |
* Copyright 1999-2010 University of Chicago |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 |
* express or implied. |
| 12 |
* |
| 13 |
* See the License for the specific language governing permissions and limitations under the License. |
| 14 |
*/ |
| 15 |
package org.globus.gsi.filestore; |
| 16 |
|
| 17 |
import static org.junit.Assert.assertFalse; |
| 18 |
import static org.junit.Assert.assertTrue; |
| 19 |
import org.globus.gsi.stores.ResourceSigningPolicy; |
| 20 |
import org.globus.gsi.testutils.FileSetupUtil; |
| 21 |
import java.util.Collection; |
| 22 |
import org.globus.gsi.SigningPolicy; |
| 23 |
import org.globus.util.GlobusResource; |
| 24 |
import org.junit.After; |
| 25 |
import org.junit.Before; |
| 26 |
import org.junit.Test; |
| 27 |
|
| 28 |
/** |
| 29 |
* FILL ME |
| 30 |
* |
| 31 |
* @author [email protected] |
| 32 |
*/ |
| 33 |
public class TestFileBasedSigningPolicy { |
| 34 |
|
| 35 |
FileSetupUtil testPolicy1; |
| 36 |
|
| 37 |
@Before |
| 38 |
public void setUp() throws Exception { |
| 39 |
|
| 40 |
// JGLOBUS-103 |
| 41 |
this.testPolicy1 = |
| 42 |
new FileSetupUtil( |
| 43 |
"certificateUtilTest/validPolicy1.signing_policy"); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
@Test |
| 48 |
public void testSigningPolicy() throws Exception { |
| 49 |
|
| 50 |
this.testPolicy1.copyFileToTemp(); |
| 51 |
|
| 52 |
ResourceSigningPolicy filePolicy = |
| 53 |
new ResourceSigningPolicy(new GlobusResource(testPolicy1.getAbsoluteFilename())); |
| 54 |
|
| 55 |
Collection<SigningPolicy> policies = filePolicy.getSigningPolicies(); |
| 56 |
|
| 57 |
assert (policies != null); |
| 58 |
|
| 59 |
assert (policies.size() == 2); |
| 60 |
|
| 61 |
// assert policy values here |
| 62 |
assertFalse(filePolicy.hasChanged()); |
| 63 |
|
| 64 |
policies = filePolicy.getSigningPolicies(); |
| 65 |
|
| 66 |
assert (policies != null); |
| 67 |
|
| 68 |
assertFalse(filePolicy.hasChanged()); |
| 69 |
|
| 70 |
testPolicy1.modifyFile(); |
| 71 |
|
| 72 |
policies = filePolicy.getSigningPolicies(); |
| 73 |
|
| 74 |
assert (policies != null); |
| 75 |
|
| 76 |
assertTrue(filePolicy.hasChanged()); |
| 77 |
} |
| 78 |
|
| 79 |
// @Test |
| 80 |
// public void testPolicyFilter() { |
| 81 |
// |
| 82 |
// FilenameFilter filter = new SigningPolicyFilter(); |
| 83 |
// |
| 84 |
// // Null checks |
| 85 |
// boolean worked = false; |
| 86 |
// try { |
| 87 |
// filter.accept(null, null); |
| 88 |
// } catch (IllegalArgumentException e) { |
| 89 |
// worked = true; |
| 90 |
// } |
| 91 |
// assert worked; |
| 92 |
// |
| 93 |
// // null dir name |
| 94 |
// assert (filter.accept(null, "foo.signing_policy")); |
| 95 |
// |
| 96 |
// // dir name ignored |
| 97 |
// assert (filter.accept(new File("bar"), "foo.signing_policy")); |
| 98 |
// |
| 99 |
// assertFalse(filter.accept(null, "foo.r")); |
| 100 |
// |
| 101 |
// assertFalse(filter.accept(null, "foo.SIGNING_POLICY")); |
| 102 |
// |
| 103 |
// assertFalse(filter.accept(null, "foo.signing")); |
| 104 |
// |
| 105 |
// } |
| 106 |
|
| 107 |
@After |
| 108 |
public void tearDown() throws Exception { |
| 109 |
this.testPolicy1.deleteFile(); |
| 110 |
} |
| 111 |
|
| 112 |
} |