(file) Return to test_wsman_inproc.cpp CVS log (file) (dir) Up to [OMI] / omi / tests / wsman

  1 krisbash 1.1 /*
  2              **==============================================================================
  3              **
  4              ** Open Management Infrastructure (OMI)
  5              **
  6              ** Copyright (c) Microsoft Corporation
  7              ** 
  8              ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9              ** use this file except in compliance with the License. You may obtain a copy 
 10              ** of the License at 
 11              **
 12              **     http://www.apache.org/licenses/LICENSE-2.0 
 13              **
 14              ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15              ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16              ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17              ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18              **
 19              ** See the Apache 2 License for the specific language governing permissions 
 20              ** and limitations under the License.
 21              **
 22 krisbash 1.1 **==============================================================================
 23              */
 24              
 25              #include <vector>
 26              #include <set>
 27              #include <cstdlib>
 28              #include <iostream>
 29              #include <ut/ut.h>
 30              #include <wsman/wsman.h>
 31              #include <sock/sock.h>
 32              #include <pal/thread.h>
 33              #include <pal/format.h>
 34              #include <base/user.h>
 35              #include "utils.h"
 36              #include <base/log.h>
 37              
 38              using namespace std;
 39              //using namespace mi;
 40              
 41              static WSMAN* s_wsman;
 42              static bool      s_running;
 43 krisbash 1.1 static Thread s_t;
 44              static Selector    s_selector;
 45              static MI_Uint16 PORT = ut::getUnittestPortNumber() + 30;
 46              
 47              #if defined(_MSC_VER)
 48              #undef BEGIN_EXTERNC
 49              #undef END_EXTERNC
 50              #define BEGIN_EXTERNC
 51              #define END_EXTERNC
 52              #endif
 53              
 54              static void _StopWSMAN()
 55              {
 56                  if (s_running)
 57                  {
 58                      s_running = false;
 59              
 60                      PAL_Uint32 ret;
 61                      UT_ASSERT(Thread_Join(&s_t, &ret) == 0);
 62                      Thread_Destroy( &s_t );
 63              
 64 krisbash 1.1         UT_ASSERT( MI_RESULT_OK == Selector_RemoveAllHandlers(&s_selector) );
 65                      UT_ASSERT( MI_RESULT_OK == WSMAN_Delete(s_wsman) );
 66              
 67                      s_wsman = 0;
 68                  }
 69              }
 70              
 71              NitsSetup(Wsman_Inproc_Setup)
 72              {
 73              #if defined(CONFIG_POSIX)
 74                  /* Disable Auth for unit-tests */
 75                  IgnoreAuthCalls(1);
 76              #endif
 77                  //PORT++;
 78              
 79                  Sock_Start();
 80                  Selector_Init(&s_selector);
 81                  Timer_SetSelector(&s_selector);
 82              }
 83              NitsEndSetup
 84              
 85 krisbash 1.1 NitsCleanup(Wsman_Inproc_Setup)
 86              {
 87                  _StopWSMAN();
 88              
 89                  Selector_Destroy(&s_selector);
 90                  Sock_Stop();
 91              }
 92              NitsEndCleanup
 93              
 94              BEGIN_EXTERNC
 95              static void* MI_CALL _WSMANServerProc(void* )
 96              {
 97                  // pump messages
 98                  for (; s_running; )
 99                      WSMAN_Run( s_wsman, SELECT_BASE_TIMEOUT_MSEC * 1000 );
100              
101                  return 0;
102              }
103              END_EXTERNC
104              
105              static void _StartWSMAN(
106 krisbash 1.1     OpenCallback callback, 
107                  void* callbackData, 
108                  WSMAN_Options* options = 0)
109              {
110                  if (s_running)
111                      return;
112              
113                  s_running = true;
114              
115                  UT_ASSERT( MI_RESULT_OK ==  WSMAN_New_Listener(
116                      &s_wsman,
117                      &s_selector,
118                      PORT,
119                      0,
120                      NULL,
121                      (Server_SSL_Options) 0,
122                      callback, 
123                      callbackData,
124                      options));
125              
126                  UT_ASSERT(MI_RESULT_OK == Thread_CreateJoinable(
127 krisbash 1.1         &s_t, (ThreadProc)_WSMANServerProc, NULL, 0));
128              
129              }
130              
131              BEGIN_EXTERNC
132              static string _CreateEnumRequestXML(
133                  const char* cn )
134              {
135                  string res = 
136              "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\""
137              "   xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\""
138              "   xmlns:n=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\""
139              "   xmlns:w=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\">"
140              "<s:Header>"
141              "<a:To>http://linux-22kv:22000/wsman</a:To>"
142              "<w:ResourceURI s:mustUnderstand=\"true\">http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/";
143              
144                  res += cn;
145                  res +=
146              "</w:ResourceURI>"
147              "<a:ReplyTo>"
148 krisbash 1.1 "<a:Address s:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>"
149              "</a:ReplyTo>"
150              "<a:Action s:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate</a:Action>"
151              "<w:MaxEnvelopeSize s:mustUnderstand=\"true\">10240</w:MaxEnvelopeSize>"
152              "<a:MessageID>uuid:FEF3DF41-FFEC-4ABE-ADFC-A8305DAB71C9</a:MessageID>"
153              "<w:Locale xml:lang=\"en-US\" s:mustUnderstand=\"false\" /><w:SelectorSet>"
154              "<w:Selector Name=\"__cimnamespace\">"
155              "ns"
156              "</w:Selector>"
157              "</w:SelectorSet>"
158              "<w:OperationTimeout>PT60.000S</w:OperationTimeout>"
159              "</s:Header>"
160              "<s:Body>"
161              "<n:Enumerate>"
162              "<w:MaxElements>10</w:MaxElements>"
163              "</n:Enumerate></s:Body></s:Envelope>"
164              ;
165                
166                  return res;
167              }
168              END_EXTERNC
169 krisbash 1.1 
170              BEGIN_EXTERNC
171              static string _CreateReleaseRequestXML(const string& ctxID)
172              {
173                  string res = 
174              "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\""
175              "   xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\""
176              "   xmlns:n=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\""
177              "   xmlns:w=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\">"
178              "<s:Header>"
179              "<a:To>http://linux-22kv:22000/wsman</a:To>"
180              "<w:ResourceURI s:mustUnderstand=\"true\">http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
181              "cn"
182              "</w:ResourceURI>"
183              "<a:ReplyTo>"
184              "<a:Address s:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>"
185              "</a:ReplyTo>"
186              "<a:Action s:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/09/enumeration/Release</a:Action>"
187              "<w:MaxEnvelopeSize s:mustUnderstand=\"true\">10240</w:MaxEnvelopeSize>"
188              "<a:MessageID>uuid:FEF3DF41-FFEC-4ABE-ADFC-A8305DAB71C9</a:MessageID>"
189              "<w:Locale xml:lang=\"en-US\" s:mustUnderstand=\"false\" /><w:SelectorSet>"
190 krisbash 1.1 "<w:Selector Name=\"__cimnamespace\">"
191              "ns"
192              "</w:Selector>"
193              "</w:SelectorSet>"
194              "<w:OperationTimeout>PT60.000S</w:OperationTimeout>"
195              "</s:Header>"
196              "<s:Body>"
197              "<n:Release>"
198              "<wsen:EnumerationContext xmlns:wsen=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\">";
199                  
200                  res += ctxID;
201                  res += 
202              "</wsen:EnumerationContext>"
203              "</n:Release>"
204              "</s:Body></s:Envelope>"
205              ;
206               
207                  return res;
208              }
209              END_EXTERNC
210              
211 krisbash 1.1 BEGIN_EXTERNC
212              void PrintProviderMsg( _In_ Message* msg)
213              {
214              }
215              
216              static void _StrandTestAck( _In_ Strand* self) 
217              {
218                  // do nothing
219              }
220              
221              static void _StrandTestFinished( _In_ Strand* self) 
222              {
223                  // do nothing
224              }
225              
226              static StrandFT strandUserFT1 = { 
227                      NULL, 
228                      NULL, 
229                      _StrandTestAck, 
230                      NULL, 
231                      NULL, 
232 krisbash 1.1         _StrandTestFinished,
233                      NULL, 
234                      NULL, 
235                      NULL, 
236                      NULL, 
237                      NULL };
238                      
239              static Strand simpleResult;
240              
241              STRAND_DEBUGNAME( TestWsman );
242              
243              static void _callback(
244                  _Inout_     InteractionOpenParams*    interactionParams )
245              {
246                  // reply with result 
247                  MI_Result r = (MI_Result) (long)interactionParams->callbackData;
248              
249                  PostResultMsg* resp = NULL;
250              
251                  UT_ASSERT (interactionParams->msg != 0);
252                  if(interactionParams->msg == 0)
253 krisbash 1.1     {
254                      Strand_FailOpen(interactionParams);
255                      return;
256                  }
257                  
258                  resp = PostResultMsg_New( interactionParams->msg->operationId );
259              
260                  UT_ASSERT (resp != 0);
261              
262                  resp->result = r;
263              
264                  Strand_Init( STRAND_DEBUG( TestWsman ) &simpleResult, &strandUserFT1, STRAND_FLAG_ENTERSTRAND, interactionParams );
265              
266                  Strand_Ack( &simpleResult );   // Ack open
267                  Strand_Post( &simpleResult, &resp->base );
268                  Strand_Close( &simpleResult );   
269                  
270                  PostResultMsg_Release(resp);
271              }
272              END_EXTERNC
273              
274 krisbash 1.1 // These tests startup wsman for 1 second and 
275              // try to send receive packets within that
276              // when run with fault injection, it will take lot of test code synchronization 
277              // for these to work; i am not adding that since other tests already cover these code paths
278              // and so just doing lot of test code changes for fault injecting these tests does not seem worth
279              NitsTestWithSetup(TestWSMAN_EnumPull, Wsman_Inproc_Setup)
280              {
281                  NitsDisableFaultSim;
282              
283                  _StartWSMAN( _callback, (void*)MI_RESULT_OK);
284              
285                  // send enum request, expect enum context back (since no OptimzeEnum tag specified)
286                  Sock s = SockConnectLocal(PORT);
287                  string r_b, r_h;
288              
289                  SockSendRecvHTTP(s, false, _CreateEnumRequestXML("InvalidClassname"), r_h, r_b );
290              
291                  UT_ASSERT(r_b.find("wsen:EnumerationContext") != string::npos);
292              
293                  string ctxID = GetCtxID(r_b);
294              
295 krisbash 1.1     UT_ASSERT(!ctxID.empty());
296              
297                  // send pull request, expecting 'ok' back
298                  SockSendRecvHTTP(s, false, CreatePullRequestXML(ctxID), r_h, r_b );
299              
300                  UT_ASSERT(r_b.find("wsen:EndOfSequence") != string::npos);
301              
302                  Sock_Close(s);
303              }
304              NitsEndTest
305              
306              NitsTestWithSetup(TestWSMAN_EnumRelease, Wsman_Inproc_Setup)
307              {
308                  NitsDisableFaultSim;
309              
310                  _StartWSMAN( _callback, (void*)MI_RESULT_OK);
311              
312                  // send enum request, expect enum context back (since no OptimzeEnum tag specified)
313                  Sock s = SockConnectLocal(PORT);
314                  string r_b, r_h;
315              
316 krisbash 1.1     SockSendRecvHTTP(s, false, _CreateEnumRequestXML("InvalidClassname"), r_h, r_b );
317                 
318                  UT_ASSERT(r_b.find("wsen:EnumerationContext") != string::npos);
319              
320                  string ctxID = GetCtxID(r_b);
321              
322                  UT_ASSERT(!ctxID.empty());
323              
324                  // send release request, expecting 'ok' back
325                  SockSendRecvHTTP(s, false, _CreateReleaseRequestXML(ctxID), r_h, r_b );
326              
327                  UT_ASSERT(r_b.find("ReleaseResponse") != string::npos);
328              
329                  // send pull and verify context is invalid
330                  SockSendRecvHTTP(s, false, CreatePullRequestXML(ctxID), r_h, r_b );
331              
332                  UT_ASSERT(r_b.find("wsa:DestinationUnreachable") != string::npos);
333                  UT_ASSERT(r_b.find("Enumeration context not found") != string::npos);
334              
335                  Sock_Close(s);
336              }
337 krisbash 1.1 NitsEndTest
338              
339              NitsTestWithSetup(TestWSMAN_PullWithInvalidCtxID, Wsman_Inproc_Setup)
340              {
341                  NitsDisableFaultSim;
342              
343                  _StartWSMAN( _callback, (void*)MI_RESULT_OK);
344              
345                  // send enum request, expect enum context back (since no OptimzeEnum tag specified)
346                  Sock s = SockConnectLocal(PORT);
347                  string r_b, r_h;
348              
349                  // sedn pull request with invalid ctx id, expecting 'error' back
350                  SockSendRecvHTTP(s, false, CreatePullRequestXML("invalid"), r_h, r_b );
351                  UT_ASSERT(r_b.find("wsa:DestinationUnreachable") != string::npos);
352                  UT_ASSERT(r_b.find("Enumeration context not found") != string::npos);
353              
354                  //cout << r_h << endl << r_b <<endl;
355                  Sock_Close(s);
356              }
357              NitsEndTest
358 krisbash 1.1 

ViewCVS 0.9.2