Debian Codegraph @

ssl-proxies/src/test/java/org/globus/gsi/filestore/TestFileBasedTrustAnchor.java

raw
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.ResourceTrustAnchor;
20 import org.globus.gsi.testutils.FileSetupUtil;
21
22 import java.io.File;
23 import java.security.cert.TrustAnchor;
24 import java.security.cert.X509Certificate;
25 import org.globus.common.CoGProperties;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 /**
31 * FILL ME
32 *
33 * @author [email protected]
34 */
35 public class TestFileBasedTrustAnchor {
36
37 FileSetupUtil testCert1;
38
39 @Before
40 public void setUp() throws Exception {
41
42 CoGProperties.getDefault().setProperty(CoGProperties.CRL_CACHE_LIFETIME, "1");
43 CoGProperties.getDefault().setProperty(CoGProperties.CERT_CACHE_LIFETIME, "1");
44 this.testCert1 = new FileSetupUtil("certificateUtilTest/1c3f2ca8.0");
45 }
46
47
48 @Test
49 public void testGetTrustAnchor() throws Exception {
50
51 this.testCert1.copyFileToTemp();
52
53 String tempFileURL = this.testCert1.getURL().toExternalForm();
54
55 ResourceTrustAnchor fileAnchor = new ResourceTrustAnchor("classpath:/certificateUtilTest/1c3f2ca8.0");
56
57 // assert (fileAnchor != null);
58
59 TrustAnchor anchor = fileAnchor.getSecurityObject();
60
61 assert (anchor != null);
62
63 X509Certificate cert = anchor.getTrustedCert();
64 assert (cert != null);
65
66 assertFalse(fileAnchor.hasChanged());
67
68 anchor = fileAnchor.getSecurityObject();
69
70 assert (anchor != null);
71
72 assertFalse(fileAnchor.hasChanged());
73
74 fileAnchor = new ResourceTrustAnchor(tempFileURL);
75
76 this.testCert1.modifyFile();
77
78 anchor = fileAnchor.getSecurityObject();
79
80 assert (anchor != null);
81
82 assertTrue(fileAnchor.hasChanged());
83
84 }
85
86
87 // @Test
88 // public void testGetTrustAnchorFilter() {
89 //
90 // FilenameFilter filter = new TrustAnchorFilter();
91 //
92 // // Null checks
93 // boolean worked = false;
94 // try {
95 // filter.accept(null, null);
96 // } catch (IllegalArgumentException e) {
97 // worked = true;
98 // }
99 // assert worked;
100 //
101 // // null dir name
102 // assert (filter.accept(null, "foo.1"));
103 //
104 // // dir name ignored
105 // assert (filter.accept(new File("bar"), "foo.9"));
106 //
107 // // only single digit at end
108 // assertFalse(filter.accept(null, "foo.10"));
109 //
110 // // only single digit at end
111 // assertFalse(filter.accept(null, "foo.bar"));
112 //
113 // // the most common usage. *.0
114 // assertTrue(filter.accept(null, "foo.0"));
115 //
116 // }
117 public static boolean deleteDir(File dir) {
118 if (dir.isDirectory()) {
119 String[] dirContent = dir.list();
120 for (int i=0; i<dirContent.length; i++){
121 boolean success = deleteDir(new File(dir, dirContent[i]));
122 if (!success) {
123 return false;
124 }
125 }
126 } // The directory is now empty so delete it
127 return dir.delete();
128 }
129 @After
130 public void tearDown() {
131
132 //this.testCert1.deleteFile();
133 deleteDir(this.testCert1.getTempFile());
134 }
135 }