|
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 "updateentrystep.h" |
|
17 |
|
18 #include <x509cert.h> |
|
19 |
|
20 const TInt KDefaultResponseDelay = 3; |
|
21 |
|
22 CUpdateEntryStep::CUpdateEntryStep() |
|
23 : iResponseDelay(KDefaultResponseDelay) |
|
24 { |
|
25 SetTestStepName(KUpdateEntryStep); |
|
26 } |
|
27 |
|
28 TVerdict CUpdateEntryStep::doTestStepPreambleL() |
|
29 { |
|
30 // Initialise the tests |
|
31 InitializeL(); |
|
32 |
|
33 // Parse the parameters required |
|
34 _LIT(KCertEntryApproved, "approved"); |
|
35 _LIT(KResponseDelay, "delay"); |
|
36 _LIT(KCancel, "cancelled"); |
|
37 _LIT(KCertEntryDenied, "denied"); |
|
38 _LIT(KMessageFmt, "Certificate entry will be %S with a delay of %d seconds."); |
|
39 |
|
40 // Ignore return code from GetBoolFromConfig to keep default of EFalse. |
|
41 GetBoolFromConfig(ConfigSection(), KCancel, iCancel); |
|
42 |
|
43 // Ignore return status from GetIntFromConfig to keep default value. |
|
44 GetIntFromConfig(ConfigSection(), KResponseDelay, iResponseDelay); |
|
45 |
|
46 if (iCancel) |
|
47 { |
|
48 Logger().WriteFormat(KMessageFmt, &KResponseDelay, iResponseDelay); |
|
49 } |
|
50 else if (!GetBoolFromConfig(ConfigSection(), KCertEntryApproved, iApproveEntry)) |
|
51 { |
|
52 _LIT(KErrorMessage, "Could not read certificate approval status from INI, abort."); |
|
53 Logger().Write(KErrorMessage); |
|
54 |
|
55 SetTestStepResult(EAbort); |
|
56 return EAbort; |
|
57 } |
|
58 else if (iApproveEntry) |
|
59 { |
|
60 Logger().WriteFormat(KMessageFmt, &KCertEntryApproved, iResponseDelay); |
|
61 } |
|
62 else |
|
63 { |
|
64 Logger().WriteFormat(KMessageFmt, &KCertEntryDenied, iResponseDelay); |
|
65 } |
|
66 |
|
67 |
|
68 return EPass; |
|
69 |
|
70 } |
|
71 |
|
72 TVerdict CUpdateEntryStep::doTestStepL() |
|
73 { |
|
74 |
|
75 // don't continue if previous phases have aborted |
|
76 if (TestStepResult() != EPass) |
|
77 { |
|
78 return TestStepResult(); |
|
79 } |
|
80 |
|
81 // Entry state should be ENewEntry at this point. |
|
82 TCacheEntryState state = Session().GetStateL(); |
|
83 |
|
84 if (state != ENewEntry) |
|
85 { |
|
86 _LIT(KMessageFormat, "State of cache entry for certificate '%S' is %d, but should be %d (ENewEntry)."); |
|
87 Logger().WriteFormat(KMessageFormat, SubjectLC(), state, ENewEntry); |
|
88 CleanupStack::PopAndDestroy(1); // subject |
|
89 SetTestStepResult(EFail); |
|
90 return EFail; |
|
91 } |
|
92 else |
|
93 { |
|
94 _LIT(KMessageFormat, "State of cache entry for certificate '%S' is ENewEntry."); |
|
95 Logger().WriteFormat(KMessageFormat, SubjectLC()); |
|
96 CleanupStack::PopAndDestroy(1); // subject |
|
97 } |
|
98 |
|
99 // Wait specifed number of seconds |
|
100 User::After(iResponseDelay * 1000000); |
|
101 |
|
102 if (iCancel) |
|
103 { |
|
104 Session().Cancel(); |
|
105 // log the action |
|
106 _LIT(KMessageFormat, "Cancelled cert cache session opened for certificate '%S'."); |
|
107 Logger().WriteFormat(KMessageFormat, SubjectLC()); |
|
108 CleanupStack::PopAndDestroy(1); // subject |
|
109 } |
|
110 else |
|
111 { |
|
112 Session().SetStateL(iApproveEntry ? EEntryApproved : EEntryDenied); |
|
113 // log the action |
|
114 _LIT(KMessageFormat, "Updated cache entry for certificate '%S'."); |
|
115 Logger().WriteFormat(KMessageFormat, SubjectLC()); |
|
116 CleanupStack::PopAndDestroy(1); // subject |
|
117 } |
|
118 |
|
119 |
|
120 SetTestStepResult(EPass); |
|
121 return EPass; |
|
122 } |
|
123 |
|
124 TVerdict CUpdateEntryStep::doTestStepPostambleL() |
|
125 { |
|
126 if (TestStepResult() == EPass) |
|
127 { |
|
128 _LIT(KMessage, "Step suceeded."); |
|
129 Logger().Write(KMessage); |
|
130 return EPass; |
|
131 } |
|
132 else |
|
133 { |
|
134 _LIT(KMessage, "Step failed."); |
|
135 Logger().Write(KMessage); |
|
136 return EFail; |
|
137 } |
|
138 } |