email/pop3andsmtpmtm/popservermtm/test/src/ctestpopsaslauthhelper.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 #include "ctestpopsaslauthhelper.h"
       
    17 
       
    18 #if defined (__WINS__)
       
    19 	#define PDD_NAME		_L("ECDRV")
       
    20 	#define LDD_NAME		_L("ECOMM")
       
    21 #else
       
    22 	#define PDD_NAME		_L("EUART1")
       
    23 	#define LDD_NAME		_L("ECOMM")
       
    24 #endif
       
    25 
       
    26 _LIT(KPopsComponent,"T_POPAuthCRAM-MD5Support");
       
    27 
       
    28 _LIT(KPOPServer,"msexchange01.closedtest.intra");
       
    29 _LIT8(KPOPUsernamePasswd, "pop001");
       
    30 
       
    31 RTest testPop3Auth(KPopsComponent);
       
    32 
       
    33 
       
    34 CTestPopSaslAuthHelper::CTestPopSaslAuthHelper()
       
    35 	{
       
    36 	}
       
    37 
       
    38 CTestPopSaslAuthHelper ::~CTestPopSaslAuthHelper()
       
    39 	{
       
    40 	}
       
    41 	
       
    42 void CTestPopSaslAuthHelper::SetupL()
       
    43 	{
       
    44 	_LIT(KFunction, "SetupL");
       
    45 	INFO_PRINTF1(KFunction);
       
    46 	
       
    47 	iResponseBuffer = HBufC8::NewL(KImMailMaxBufferSize);
       
    48 	}
       
    49 
       
    50 void CTestPopSaslAuthHelper::TearDownL()
       
    51 	{
       
    52 	_LIT(KFunction, "TearDownL");
       
    53 	INFO_PRINTF1(KFunction);
       
    54 	
       
    55 	delete iResponseBuffer;
       
    56 	delete iPopSettings;
       
    57 	delete iActiveWaiter;
       
    58 	delete iTestUtils;
       
    59 	}
       
    60 	
       
    61 	
       
    62 void CTestPopSaslAuthHelper::CreatePopSaslAuthMechanismL()
       
    63 	{
       
    64 	CreatePopTestAccountL();
       
    65 	ConnectToRemoteServerL();
       
    66 	TestForAuthCramMd5L();
       
    67 	TestForAuthPlainL();
       
    68 	TestForAuthLoginL();
       
    69 	DisconnectL();
       
    70 	}
       
    71 
       
    72 void CTestPopSaslAuthHelper::CreatePopTestAccountL()
       
    73 	{
       
    74 	_LIT(KFunction, "CreatePopTestAccountL");
       
    75 	INFO_PRINTF1(KFunction);
       
    76 	
       
    77 	TInt err;
       
    78 	err=User::LoadPhysicalDevice(PDD_NAME);
       
    79 	if (err!=KErrNone && err!=KErrAlreadyExists)
       
    80 		User::Leave(err);
       
    81 	err=User::LoadLogicalDevice(LDD_NAME);
       
    82 	if (err!=KErrNone && err!=KErrAlreadyExists)
       
    83 		User::Leave(err);
       
    84 	
       
    85 	iActiveWaiter = new(ELeave)CActiveWaiter();
       
    86 	
       
    87 	iTestUtils = CEmailTestUtils::NewL(testPop3Auth);
       
    88 	iTestUtils->FileSession().SetSessionPath( _L( "C:\\" ) );
       
    89 	iTestUtils->ClearEmailAccountsL();
       
    90 	iTestUtils->CreateAllTestDirectories();
       
    91 	iTestUtils->CleanMessageFolderL();
       
    92 	
       
    93 	iTestUtils->GoClientSideL();	
       
    94 
       
    95 	if(!iPop3Service)
       
    96 		{
       
    97 		iPop3Service = iTestUtils->CreatePopServiceL();	
       
    98 		}
       
    99 		
       
   100 	iEmailAccount = CEmailAccounts::NewLC();
       
   101 	iPopSettings = new(ELeave) CImPop3Settings();
       
   102 
       
   103 	CImIAPPreferences* imapIAP = CImIAPPreferences::NewLC();
       
   104 	iEntrySelection = new (ELeave) CMsvEntrySelection;
       
   105 
       
   106 	
       
   107 	iEmailAccount->GetPopAccountL(iPop3Service, iPop3AccountId);
       
   108   	iEmailAccount->LoadPopSettingsL(iPop3AccountId, *iPopSettings);
       
   109 
       
   110 	iPopSettings->SetServerAddressL(KPOPServer);
       
   111 	iPopSettings->SetLoginNameL(KPOPUsernamePasswd /*iTestUtils->MachineName()*/);
       
   112 	iPopSettings->SetPasswordL(KPOPUsernamePasswd /*iTestUtils->MachineName()*/);
       
   113 	iPopSettings->SetPort(110);
       
   114 	iPopSettings->SetPOP3Auth(ETrue);
       
   115 	iPopSettings->SetFallBack(ETrue);
       
   116 
       
   117 	iEmailAccount->SavePopSettingsL(iPop3AccountId, *iPopSettings);
       
   118 	CleanupStack::PopAndDestroy(2, iEmailAccount);
       
   119 	
       
   120 	iTestUtils->GoServerSideL();
       
   121 	iTestUtils->InstantiatePopServerMtmL();
       
   122 	iPopServerMtm = iTestUtils->iPopServerMtm;
       
   123 	}
       
   124 	
       
   125 
       
   126 //Connect to Remote Server 
       
   127 void CTestPopSaslAuthHelper::ConnectToRemoteServerL()
       
   128 	{
       
   129 	_LIT(KFunction, "ConnectToRemoteServerL");
       
   130 	INFO_PRINTF1(KFunction);
       
   131 	
       
   132 	TBuf8<128> parameter;
       
   133 	iEntrySelection->AppendL(iPop3Service);
       
   134 	TPop3Progress temp;	
       
   135 	TPckgC<TPop3Progress> paramPack(temp);
       
   136 	
       
   137 	iPopServerMtm->StartCommandL(*iEntrySelection, KPOP3MTMConnect, parameter, iActiveWaiter->iStatus);
       
   138 	iActiveWaiter->WaitActive();
       
   139 	
       
   140 	const TDesC8& progBuf = iTestUtils->iPopServerMtm->Progress();	
       
   141 	paramPack.Set(progBuf);
       
   142 	TPop3Progress progress=paramPack();	
       
   143 	
       
   144 	ASSERT_EQUALS( progress.iErrorCode, KErrNone );
       
   145 	}
       
   146 	
       
   147 //Disconnecting from Remote Server
       
   148 void CTestPopSaslAuthHelper::DisconnectL()
       
   149 	{
       
   150 	_LIT(KFunction, "DisconnectL");
       
   151 	INFO_PRINTF1(KFunction);
       
   152 	
       
   153 	TBuf8<128> parameter;
       
   154 	iEntrySelection->AppendL(iPop3Service);
       
   155 	iPopServerMtm->StartCommandL(*iEntrySelection,KPOP3MTMDisconnect , parameter, iActiveWaiter->iStatus);
       
   156 	iActiveWaiter->WaitActive();
       
   157 	
       
   158 	ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone );
       
   159 	}
       
   160 
       
   161 void CTestPopSaslAuthHelper::TestForAuthCramMd5L()
       
   162 	{
       
   163 	// For CRAM-MD5
       
   164 	_LIT(KFunction, "TestForAuthCramMd5L");
       
   165 	INFO_PRINTF1(KFunction);
       
   166 
       
   167 	iTestPopAuthMechanism = CPopAuthCramMd5MechanismHelper::NewL(*iPopSettings);
       
   168 	CleanupStack::PushL(iTestPopAuthMechanism);
       
   169 	TPtr8 popBuffer = iResponseBuffer->Des();
       
   170 	
       
   171 	//popBuffer will contain "AUTH CRAM-MD5"
       
   172 	iTestPopAuthMechanism->GetNextClientMessageL(popBuffer);
       
   173 	//INFO_PRINTF1(popBuffer);
       
   174 			
       
   175 	//set dummy server response
       
   176 	_LIT(KServerResponse,"+ PDE4LjEyMjYzOTQ0MDZARDA3MDAzMS5wcm9kLmFkLnN5bWJpYW4uaW50cmE+");
       
   177 	popBuffer.Append(KServerResponse);
       
   178 	
       
   179 	iTestPopAuthMechanism->SetLastServerMessageL(popBuffer, ETrue);
       
   180 		
       
   181 	//popBuffer will contain CRAM-MD5 authentication string
       
   182 	iTestPopAuthMechanism->GetNextClientMessageL(popBuffer);
       
   183 	
       
   184 	//check the length of response buffer 
       
   185 	TInt error = (popBuffer.Length() > 0 ) ? KErrNone : KErrArgument;
       
   186 	ASSERT_EQUALS(error, KErrNone);	
       
   187 	
       
   188 	CleanupStack::PopAndDestroy(iTestPopAuthMechanism);
       
   189 	}
       
   190 
       
   191 void CTestPopSaslAuthHelper::TestForAuthPlainL()
       
   192 	{
       
   193 	// For PLAIN
       
   194 	_LIT(KFunction, "TestForAuthPlainL");
       
   195 	INFO_PRINTF1(KFunction);
       
   196 	
       
   197 	iTestPopAuthMechanism = CPopAuthPlainMechanismHelper::NewL(*iPopSettings);
       
   198 	CleanupStack::PushL(iTestPopAuthMechanism);
       
   199 	
       
   200 	TPtr8 popBuffer = iResponseBuffer->Des();
       
   201 	iTestPopAuthMechanism->GetNextClientMessageL(popBuffer);
       
   202 	
       
   203 	//check the length of response buffer 
       
   204 	TInt error = (popBuffer.Length() > 0 ) ? KErrNone : KErrArgument;
       
   205 	ASSERT_EQUALS(error, KErrNone);	
       
   206 		
       
   207 	CleanupStack::PopAndDestroy(iTestPopAuthMechanism);
       
   208 	}
       
   209 
       
   210 void CTestPopSaslAuthHelper::TestForAuthLoginL()
       
   211 	{
       
   212 	// For LOGIN
       
   213 	_LIT(KFunction, "TestForAuthLoginL");
       
   214 	INFO_PRINTF1(KFunction);
       
   215 	
       
   216 	iTestPopAuthMechanism = CPopAuthLoginMechanismHelper::NewL(*iPopSettings);
       
   217 	CleanupStack::PushL(iTestPopAuthMechanism);
       
   218 	
       
   219 	TPtr8 popBuffer = iResponseBuffer->Des();
       
   220 	iTestPopAuthMechanism->GetNextClientMessageL(popBuffer);
       
   221 	
       
   222 	//set dummy server response for Username
       
   223 	popBuffer.Zero();
       
   224 	_LIT(KServerResponseForUsername,"+ VXNlcm5hbWU6");
       
   225 	popBuffer.Append(KServerResponseForUsername);
       
   226 	iTestPopAuthMechanism->SetLastServerMessageL(popBuffer, ETrue);
       
   227 	
       
   228 	//popBuffer will contain Username in base64 encoded format
       
   229 	iTestPopAuthMechanism->GetNextClientMessageL(popBuffer);
       
   230 	
       
   231 	//check the length of response buffer 
       
   232 	TInt error = (popBuffer.Length() > 0 ) ? KErrNone : KErrArgument;
       
   233 	ASSERT_EQUALS(error, KErrNone);
       
   234 	
       
   235 	//set dummy server response for Password
       
   236 	popBuffer.Zero();
       
   237 	_LIT(KServerResponseForPasswd,"+ UGFzc3dvcmQ6");
       
   238 	popBuffer.Append(KServerResponseForPasswd);
       
   239 	iTestPopAuthMechanism->SetLastServerMessageL(popBuffer, ETrue);
       
   240 	
       
   241 	//popBuffer will contain Password in base64 encoded format
       
   242 	iTestPopAuthMechanism->GetNextClientMessageL(popBuffer);
       
   243 	
       
   244 	//check the length of response buffer 
       
   245 	error = (popBuffer.Length() > 0 ) ? KErrNone : KErrArgument;
       
   246 	ASSERT_EQUALS(error, KErrNone);
       
   247 	
       
   248 	CleanupStack::PopAndDestroy(iTestPopAuthMechanism);	
       
   249 	}
       
   250 
       
   251 
       
   252 CTestSuite* CTestPopSaslAuthHelper::CreateSuiteL(const TDesC& aName)
       
   253 	{
       
   254 	SUB_SUITE;
       
   255 	ADD_ASYNC_TEST_STEP(CreatePopSaslAuthMechanismL);
       
   256 	END_SUITE;
       
   257 	}
       
   258