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