|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "entrystatusstep.h" |
|
17 |
|
18 #include <x509cert.h> |
|
19 |
|
20 // Default delay before checking state |
|
21 const TInt KStateCheckDelay = 1000000; |
|
22 |
|
23 CEntryStatusStep::CEntryStatusStep() |
|
24 { |
|
25 SetTestStepName(KEntryStatus); |
|
26 } |
|
27 |
|
28 TVerdict CEntryStatusStep::doTestStepPreambleL() |
|
29 { |
|
30 InitializeL(); |
|
31 SetTestStepResult(EPass); |
|
32 |
|
33 _LIT(KRequestChangeNotify, "requestchangenotify"); |
|
34 _LIT(KCertEntryState, "state"); |
|
35 _LIT(KNewEntryString, "ENewEntry"); |
|
36 _LIT(KEntryAwaitingApprovalString, "EEntryAwaitingApproval"); |
|
37 _LIT(KEntryDeniedString, "EEntryDenied"); |
|
38 _LIT(KEntryApprovedString, "EEntryApproved"); |
|
39 _LIT(KCancelPoint, "cancelpoint"); |
|
40 _LIT(KOpen, "Open"); |
|
41 _LIT(KGetState, "GetStateL"); |
|
42 _LIT(KChangeNotify, "ChangeNotify"); |
|
43 |
|
44 TPtrC cancelPoint; |
|
45 _LIT(KCancelMessageFmt, "This test step will call Cancel() on the cert cache session after %S()"); |
|
46 if (!GetStringFromConfig(ConfigSection(), KCancelPoint, cancelPoint)) |
|
47 { |
|
48 iCancelPoint = ENoCancel; |
|
49 } |
|
50 else if (cancelPoint.CompareF(KOpen) == 0) |
|
51 { |
|
52 iCancelPoint = EAfterOpen; |
|
53 Logger().WriteFormat(KCancelMessageFmt, &KOpen); |
|
54 } |
|
55 else if (cancelPoint.CompareF(KGetState) == 0) |
|
56 { |
|
57 iCancelPoint = EAfterGetState; |
|
58 Logger().WriteFormat(KCancelMessageFmt, &KGetState); |
|
59 } |
|
60 else if (cancelPoint.CompareF(KChangeNotify) == 0) |
|
61 { |
|
62 iCancelPoint = EAfterChangeNotify; |
|
63 Logger().WriteFormat(KCancelMessageFmt, &KChangeNotify); |
|
64 } |
|
65 |
|
66 // Check if this step should wait for change notification. |
|
67 if (!GetBoolFromConfig(ConfigSection(), KRequestChangeNotify, iRequestChangeNotify)) |
|
68 { |
|
69 iRequestChangeNotify = EFalse; |
|
70 } |
|
71 else if (iRequestChangeNotify) |
|
72 { |
|
73 if (iCancelPoint == ENoCancel) |
|
74 { |
|
75 _LIT(KMessage, "This test step will wait for change notification."); |
|
76 Logger().Write(KMessage); |
|
77 } |
|
78 else if (iCancelPoint != EAfterChangeNotify) |
|
79 { |
|
80 _LIT(KErrorMessage, "Invalid test config, requesting notification but cancelling earlier."); |
|
81 Logger().Write(KErrorMessage); |
|
82 SetTestStepResult(EAbort); |
|
83 return EAbort; |
|
84 } |
|
85 |
|
86 _LIT(KRequirePendingApproval, "requirependingapproval"); |
|
87 if (!GetBoolFromConfig(ConfigSection(), KRequirePendingApproval, iRequirePendingApproval)) |
|
88 { |
|
89 iRequirePendingApproval = ETrue; |
|
90 } |
|
91 if (iRequirePendingApproval) |
|
92 { |
|
93 _LIT(KMessage2, "This step will fail if the state is not initially EEntryAwaitingApproval."); |
|
94 Logger().Write(KMessage2); |
|
95 } |
|
96 else |
|
97 { |
|
98 _LIT(KMessage2, "Notification will be requested even if the state is not initially EEntryAwaitingApproval."); |
|
99 Logger().Write(KMessage2); |
|
100 } |
|
101 } |
|
102 |
|
103 TPtrC expectedState; |
|
104 |
|
105 if (!GetStringFromConfig(ConfigSection(), KCertEntryState, expectedState)) |
|
106 { |
|
107 _LIT(KMessage, "Could not read expected certificate approval state from INI, abort."); |
|
108 Logger().Write(KMessage); |
|
109 |
|
110 SetTestStepResult(EAbort); |
|
111 } |
|
112 else |
|
113 { |
|
114 _LIT(KMessageFmt, "Certificate state is expected to be %S."); |
|
115 if (expectedState.CompareF(KNewEntryString) == 0) |
|
116 { |
|
117 iExpectedState = ENewEntry; |
|
118 Logger().WriteFormat(KMessageFmt, &KNewEntryString); |
|
119 } |
|
120 else if (expectedState.CompareF(KEntryAwaitingApprovalString) == 0) |
|
121 { |
|
122 iExpectedState = EEntryAwaitingApproval; |
|
123 Logger().WriteFormat(KMessageFmt, &KEntryAwaitingApprovalString); |
|
124 } |
|
125 else if (expectedState.CompareF(KEntryApprovedString) == 0) |
|
126 { |
|
127 iExpectedState = EEntryApproved; |
|
128 Logger().WriteFormat(KMessageFmt, &KEntryApprovedString); |
|
129 } |
|
130 else if (expectedState.CompareF(KEntryDeniedString) == 0) |
|
131 { |
|
132 iExpectedState = EEntryDenied; |
|
133 Logger().WriteFormat(KMessageFmt, &KEntryDeniedString); |
|
134 } |
|
135 else |
|
136 { |
|
137 _LIT(KMessage, "Invalid expected certificate state, abort."); |
|
138 Logger().Write(KMessage); |
|
139 SetTestStepResult(EAbort); |
|
140 } |
|
141 } |
|
142 return TestStepResult(); |
|
143 } |
|
144 |
|
145 TVerdict CEntryStatusStep::doTestStepL() |
|
146 { |
|
147 // don't continue if previous phases have aborted |
|
148 if (TestStepResult() != EPass) |
|
149 { |
|
150 return TestStepResult(); |
|
151 } |
|
152 |
|
153 // Delay briefly to ensure that any update entry steps in concurrent tests can |
|
154 // check first (which sets the state to EAwaitingApproval.) |
|
155 User::After(KStateCheckDelay); |
|
156 |
|
157 _LIT(KCancelMessage, "Cancelling..."); |
|
158 |
|
159 // Cancel if set to do so before checking state. |
|
160 if (iCancelPoint == EAfterOpen) |
|
161 { |
|
162 Logger().Write(KCancelMessage); |
|
163 Session().Cancel(); |
|
164 } |
|
165 |
|
166 iState = Session().GetStateL(); |
|
167 |
|
168 // log the action |
|
169 _LIT(KMessageFmt, "State of cache entry for certificate '%S' is %d."); |
|
170 Logger().WriteFormat(KMessageFmt, SubjectLC(), iState); |
|
171 CleanupStack::PopAndDestroy(1); // subject |
|
172 |
|
173 if (iCancelPoint == EAfterGetState) |
|
174 { |
|
175 Logger().Write(KCancelMessage); |
|
176 Session().Cancel(); |
|
177 iState = Session().GetStateL(); |
|
178 Logger().WriteFormat(KMessageFmt, SubjectLC(), iState); |
|
179 CleanupStack::PopAndDestroy(1); // subject |
|
180 } |
|
181 else if (iRequestChangeNotify) |
|
182 { |
|
183 if (iState == EEntryAwaitingApproval || !iRequirePendingApproval) |
|
184 { |
|
185 TRequestStatus status; |
|
186 Session().RequestNotify(status); |
|
187 if (iCancelPoint == EAfterChangeNotify) |
|
188 { |
|
189 Logger().Write(KCancelMessage); |
|
190 Session().Cancel(); |
|
191 } |
|
192 |
|
193 User::WaitForRequest(status); |
|
194 |
|
195 User::LeaveIfError(status.Int()); |
|
196 |
|
197 iState = Session().GetStateL(); |
|
198 |
|
199 // log the action |
|
200 _LIT(KMessageFormat, "Got cache change notify for certificate '%S', state = %d."); |
|
201 Logger().WriteFormat(KMessageFormat, SubjectLC(), iState); |
|
202 CleanupStack::PopAndDestroy(1); // certificate status |
|
203 } |
|
204 else |
|
205 { |
|
206 // log the action |
|
207 _LIT(KMessageFormat, "Cannot wait for change notify, entry state is not %d (EEntryAwaitingApproval.)"); |
|
208 Logger().WriteFormat(KMessageFormat, EEntryAwaitingApproval); |
|
209 SetTestStepResult(EFail) ; |
|
210 } |
|
211 } |
|
212 |
|
213 return TestStepResult(); |
|
214 |
|
215 } |
|
216 |
|
217 TVerdict CEntryStatusStep::doTestStepPostambleL() |
|
218 { |
|
219 |
|
220 if (TestStepResult() == EPass) |
|
221 { |
|
222 _LIT(KMessage, "Step suceeded. Checking result..."); |
|
223 Logger().Write(KMessage); |
|
224 } |
|
225 else |
|
226 { |
|
227 _LIT(KMessage, "Step failed."); |
|
228 Logger().Write(KMessage); |
|
229 return TestStepResult(); |
|
230 } |
|
231 |
|
232 if (iExpectedState == iState) |
|
233 { |
|
234 _LIT(KMessageFmt, "Expected state %d matches actual state."); |
|
235 Logger().WriteFormat(KMessageFmt, iState); |
|
236 SetTestStepResult(EPass); |
|
237 return EPass; |
|
238 } |
|
239 else |
|
240 { |
|
241 _LIT(KMessageFmt, "Expected state %d does not match actual state %d!"); |
|
242 Logger().WriteFormat(KMessageFmt, iExpectedState, iState); |
|
243 SetTestStepResult(EFail); |
|
244 return EFail; |
|
245 } |
|
246 |
|
247 } |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |