Debian Codegraph @

ssl-proxies/src/test/java/org/globus/gsi/filestore/TestFileBasedCRL.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.ResourceCRL;
20 import org.globus.gsi.testutils.FileSetupUtil;
21 import java.io.File;
22 import java.security.cert.X509CRL;
23 import org.globus.common.CoGProperties;
24 import org.globus.util.GlobusResource;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 /**
30 * FILL ME
31 *
32 * @author [email protected]
33 */
34 public class TestFileBasedCRL {
35
36 FileSetupUtil testCrl1;
37
38 @Before
39 public void setUp() throws Exception {
40
41 CoGProperties.getDefault().setProperty(CoGProperties.CRL_CACHE_LIFETIME, "1");
42 CoGProperties.getDefault().setProperty(CoGProperties.CERT_CACHE_LIFETIME, "1");
43 this.testCrl1 = new FileSetupUtil("certificateUtilTest/validCrl.r0");
44 }
45
46
47 @Test
48 public void testGetCrl() throws Exception {
49
50 this.testCrl1.copyFileToTemp();
51
52 String tempFileName = this.testCrl1.getAbsoluteFilename();
53
54 ResourceCRL fileCrl = new ResourceCRL(false, new GlobusResource(tempFileName));
55
56 // assert (fileCrl != null);
57
58 X509CRL crl = fileCrl.getCrl();
59
60 assert (crl != null);
61
62 assertFalse(fileCrl.hasChanged());
63
64 crl = fileCrl.getCrl();
65
66 assert (crl != null);
67
68 assertFalse(fileCrl.hasChanged());
69
70 this.testCrl1.modifyFile();
71
72 crl = fileCrl.getCrl();
73
74 assert (crl != null);
75
76 assertTrue(fileCrl.hasChanged());
77 }
78
79 // @Test
80 // public void testGetCrlFilter() {
81 //
82 // FilenameFilter filter = FileBasedCRL.getCrlFilter();
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.r1"));
95 //
96 // // dir name ignored
97 // assert (filter.accept(new File("bar"), "foo.r9"));
98 //
99 // // only single digit at end
100 // assertFalse(filter.accept(null, "foo.r10"));
101 //
102 // // only single digit at end
103 // assertFalse(filter.accept(null, "foo.rbar"));
104 //
105 // // the most common usage. *.0
106 // assertTrue(filter.accept(null, "foo.r0"));
107 //
108 // }
109 public static boolean deleteDir(File dir) {
110 if (dir.isDirectory()) {
111 String[] dirContent = dir.list();
112 for (int i=0; i<dirContent.length; i++){
113 boolean success = deleteDir(new File(dir, dirContent[i]));
114 if (!success) {
115 return false;
116 }
117 }
118 } // The directory is now empty so delete it
119 return dir.delete();
120 }
121 @After
122 public void tearDown() throws Exception {
123 //this.testCrl1.deleteFile();
124 deleteDir(this.testCrl1.getTempFile());
125 }
126
127 }