wlanutilities/wlanwizard/tsrc/stubs/eapqtconfiginterface_context.cpp
changeset 56 de27cc8389dd
child 58 301aeb18ae47
equal deleted inserted replaced
50:d4198dcb9983 56:de27cc8389dd
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  */
       
    16 #include <QTest>
       
    17 
       
    18 #include "eapqtconfiginterface_context.h"
       
    19 #include "eapqtvalidator_stub.h"
       
    20 #include "eapqtexpandedeaptype.h"
       
    21 
       
    22 EapQtConfigInterfaceContext::EapQtConfigInterfaceContext() : 
       
    23     mEapQtConfig(NULL)
       
    24 {
       
    25 }
       
    26 
       
    27 EapQtConfigInterfaceContext::~EapQtConfigInterfaceContext()
       
    28 {
       
    29     mEapQtConfig->mValidator.clear();
       
    30 }
       
    31 
       
    32 void EapQtConfigInterfaceContext::setObject(EapQtConfigInterface *eapQtConfig)
       
    33 {
       
    34     mEapQtConfig = eapQtConfig;
       
    35 }
       
    36 
       
    37 void EapQtConfigInterfaceContext::createEapAkaSim(int type)
       
    38 {
       
    39     QList<EapQtPluginHandle> types;
       
    40     types.append((EapQtPluginHandle::Plugin)type);
       
    41     setSupportedOuterTypes(types);
       
    42 
       
    43     setSelectectedOuterTypes(types, true);
       
    44     
       
    45     EapQtConfig config;
       
    46     config.setValue(EapQtConfig::UsernameAutomatic, true);
       
    47     config.setValue(EapQtConfig::RealmAutomatic, true);
       
    48     setOuterConfig((EapQtPluginHandle::Plugin)type, config, true);
       
    49 }
       
    50 
       
    51 void EapQtConfigInterfaceContext::createLeap(
       
    52     const QString& username, 
       
    53     const QString& passwd)
       
    54 {
       
    55     QList<EapQtPluginHandle> types;
       
    56     types.append(EapQtPluginHandle::PluginLeap);
       
    57     setSupportedOuterTypes(types);
       
    58 
       
    59     setSelectectedOuterTypes(types, true);
       
    60     
       
    61     EapQtConfig config;
       
    62     config.setValue(EapQtConfig::UsernameAutomatic, false);
       
    63     config.setValue(EapQtConfig::Username, username);
       
    64     config.setValue(EapQtConfig::PasswordPrompt, false);
       
    65     config.setValue(EapQtConfig::Password, passwd);
       
    66     setOuterConfig(EapQtPluginHandle::PluginLeap, config, true);
       
    67     
       
    68     // validators
       
    69     createInnerTypeValidators(EapQtPluginHandle::PluginLeap);
       
    70 }
       
    71 
       
    72 void EapQtConfigInterfaceContext::createEapIdentifyValidators(EapQtPluginHandle::Plugin outerType)
       
    73 {
       
    74     EapQtPluginHandle typeHandle(outerType);
       
    75     
       
    76     EapQtValidatorStub *valStub = new EapQtValidatorStub(EapQtValidator::StatusOk);
       
    77     setValidator(typeHandle.type().type(), EapQtConfig::Username, valStub);
       
    78     
       
    79     valStub = new EapQtValidatorStub(EapQtValidator::StatusOk);
       
    80     setValidator(typeHandle.type().type(), EapQtConfig::Realm, valStub);
       
    81 }
       
    82 
       
    83 void EapQtConfigInterfaceContext::createEapTtlsPeap(
       
    84     EapQtPluginHandle::Plugin type,
       
    85     bool automaticCert,
       
    86     bool usernameAutomatic, 
       
    87     const QString &username,
       
    88     bool realmAutomatic, 
       
    89     const QString &realm,
       
    90     EapQtPluginHandle::Plugin innerType)
       
    91 {
       
    92     EapQtPluginHandle typeHandle(type);
       
    93     
       
    94     QList<EapQtPluginHandle> types;
       
    95     types.append(typeHandle);
       
    96     setSupportedOuterTypes(types);
       
    97     setSelectectedOuterTypes(types, true);
       
    98     
       
    99     // Certs
       
   100     QList<EapQtCertificateInfo> certs;
       
   101     EapQtCertificateInfo caCert;
       
   102     caCert.setValue(EapQtCertificateInfo::CertificateLabel, "My Super Cert");
       
   103     certs.append(caCert);
       
   104     setCertsCa(certs);
       
   105     
       
   106     // CREATE VALIDATOR
       
   107     createEapIdentifyValidators(type);
       
   108     
       
   109     // CREATE CONFIGURATION FOR TTLS/PEAP
       
   110     
       
   111     EapQtConfig config;
       
   112     config.setValue(EapQtConfig::UseIdentityPrivacy, false);
       
   113     config.setValue(EapQtConfig::VerifyServerRealm, false);
       
   114     config.setValue(EapQtConfig::ClientAuthenticationRequired, false);
       
   115     
       
   116     config.setValue(EapQtConfig::UsernameAutomatic, usernameAutomatic);
       
   117     config.setValue(EapQtConfig::Username, username);
       
   118     config.setValue(EapQtConfig::RealmAutomatic, realmAutomatic);
       
   119     config.setValue(EapQtConfig::Realm, realm);
       
   120     if (automaticCert){
       
   121         config.setValue(EapQtConfig::AuthorityCertificateAutomatic, true);
       
   122     }
       
   123     else {
       
   124         QList<QVariant> caCerts;
       
   125         caCerts.append(qVariantFromValue(caCert));
       
   126         config.setValue(EapQtConfig::AuthorityCertificate, caCerts);
       
   127         config.setValue(EapQtConfig::AuthorityCertificateAutomatic, false);
       
   128     }
       
   129     if (type == EapQtPluginHandle::PluginPeap){
       
   130         if (innerType == EapQtPluginHandle::PluginEapMschapv2){
       
   131             config.setValue(EapQtConfig::PeapVersion0Allowed, true);
       
   132             config.setValue(EapQtConfig::PeapVersion1Allowed, false);  
       
   133         }
       
   134         else {
       
   135             config.setValue(EapQtConfig::PeapVersion0Allowed, false);
       
   136             config.setValue(EapQtConfig::PeapVersion1Allowed, true);
       
   137         }
       
   138         config.setValue(EapQtConfig::PeapVersion2Allowed, false);
       
   139     }
       
   140     QList<QVariant> innerTypeList;
       
   141     EapQtPluginHandle inner(innerType);
       
   142     innerTypeList.append(qVariantFromValue(inner));
       
   143     config.setValue(EapQtConfig::InnerType, innerTypeList);
       
   144     
       
   145     setOuterConfig(type, config, true);
       
   146 }
       
   147 
       
   148 void EapQtConfigInterfaceContext::createEapTls(
       
   149     QList<EapQtCertificateInfo> &caCerts,
       
   150     int indexForCaCert,
       
   151     QList<EapQtCertificateInfo> &userCerts,
       
   152     int indexForUserCert)
       
   153 {
       
   154     QList<EapQtPluginHandle> types;
       
   155     types.append(EapQtPluginHandle::PluginEapTls);
       
   156     setSupportedOuterTypes(types);
       
   157     setSelectectedOuterTypes(types, true);
       
   158     
       
   159     // Certs
       
   160     setCertsCa(caCerts);
       
   161     setCertsUser(userCerts);
       
   162     
       
   163     // CREATE VALIDATOR
       
   164     createEapIdentifyValidators(EapQtPluginHandle::PluginEapTls);
       
   165     
       
   166     // CREATE CONFIGURATION FOR TTLS/PEAP
       
   167     
       
   168     EapQtConfig config;
       
   169     config.setValue(EapQtConfig::UseIdentityPrivacy, false);
       
   170     config.setValue(EapQtConfig::VerifyServerRealm, false);
       
   171     config.setValue(EapQtConfig::ClientAuthenticationRequired, true);
       
   172     
       
   173     config.setValue(EapQtConfig::UsernameAutomatic, true);
       
   174     config.setValue(EapQtConfig::Username, QString());
       
   175     config.setValue(EapQtConfig::RealmAutomatic, true);
       
   176     config.setValue(EapQtConfig::Realm, QString());
       
   177     
       
   178     if (caCerts.length() == 0){
       
   179         config.setValue(EapQtConfig::AuthorityCertificateAutomatic, true);
       
   180     } else {
       
   181         QList<QVariant> caCertsVariant;
       
   182         caCertsVariant.append(qVariantFromValue(caCerts[indexForCaCert]));    
       
   183         config.setValue(EapQtConfig::AuthorityCertificate, caCertsVariant);
       
   184         config.setValue(EapQtConfig::AuthorityCertificateAutomatic, false);
       
   185     }
       
   186     
       
   187     if (indexForUserCert != -1) {
       
   188         QList<QVariant> certs;
       
   189         certs.append(qVariantFromValue(userCerts[indexForUserCert]));
       
   190         config.setValue(EapQtConfig::UserCertificate, certs);
       
   191     }
       
   192     
       
   193     setOuterConfig(EapQtPluginHandle::PluginEapTls, config, true);
       
   194 }
       
   195 
       
   196 void EapQtConfigInterfaceContext::createInner(
       
   197     EapQtPluginHandle::Plugin outerType,
       
   198     EapQtPluginHandle::Plugin innerType, 
       
   199     const QString &username,
       
   200     const QString &password)
       
   201 {
       
   202     EapQtPluginHandle innerHandle(innerType);
       
   203     
       
   204     QList<EapQtPluginHandle> types;
       
   205     types.append(innerHandle);
       
   206     setSupportedInnerTypes(outerType, types);
       
   207 
       
   208     EapQtConfig config;
       
   209     EapQtPluginHandle outerTypeHandle(outerType);
       
   210     config.setValue(EapQtConfig::OuterType, qVariantFromValue(outerTypeHandle));
       
   211     config.setValue(EapQtConfig::UsernameAutomatic, false);
       
   212     config.setValue(EapQtConfig::Username, username);
       
   213     config.setValue(EapQtConfig::PasswordPrompt, false);
       
   214     config.setValue(EapQtConfig::Password, password);
       
   215     setInnerConfig(innerType, config, true);
       
   216     
       
   217     createInnerTypeValidators(innerType);
       
   218 }
       
   219 
       
   220 void EapQtConfigInterfaceContext::createInnerTypeValidators(EapQtPluginHandle::Plugin innerType)
       
   221 {
       
   222     EapQtPluginHandle innerHandle(innerType);
       
   223     
       
   224     // validators
       
   225     EapQtValidatorStub *valStub = new EapQtValidatorStub(EapQtValidator::StatusOk);
       
   226     setValidator(innerHandle.type().type(), EapQtConfig::Username, valStub);
       
   227     
       
   228     valStub = new EapQtValidatorStub(EapQtValidator::StatusOk);
       
   229     setValidator(innerHandle.type().type(), EapQtConfig::Password, valStub);    
       
   230 }
       
   231 
       
   232 void EapQtConfigInterfaceContext::createEapFast(
       
   233     int pacState, const QString &password)
       
   234 {
       
   235     QList<EapQtPluginHandle> types;
       
   236     types.append(EapQtPluginHandle::PluginEapFast);
       
   237     setSupportedOuterTypes(types);
       
   238     setSelectectedOuterTypes(types, true);
       
   239 
       
   240     EapQtPacStoreConfig pacStoreConfig;
       
   241     pacStoreConfig.setValue(EapQtPacStoreConfig::PacStoreState, pacState);
       
   242     setPacStoreConfigRead(pacStoreConfig, true);
       
   243     
       
   244     if (pacState == EapQtPacStoreConfig::PacStoreStateStoreNotExists ||
       
   245         pacState == EapQtPacStoreConfig::PacStoreStatePasswordRequired) {
       
   246         pacStoreConfig.clear();
       
   247         pacStoreConfig.setValue(
       
   248             EapQtPacStoreConfig::PacStorePassword, 
       
   249             password);
       
   250         
       
   251         pacStoreConfig.setValue(
       
   252             EapQtPacStoreConfig::PacStoreSavePassword, 
       
   253             true);
       
   254         
       
   255         setPacStoreConfigSave(pacStoreConfig, true);
       
   256     }
       
   257     
       
   258     if (pacState == EapQtPacStoreConfig::PacStoreStateStoreNotExists) {
       
   259         EapQtValidatorStub *validator = new EapQtValidatorStub(EapQtValidator::StatusOk);
       
   260         setValidatorPacStore(EapQtPacStoreConfig::PacStorePassword, validator);
       
   261     }
       
   262 
       
   263     if (pacState == EapQtPacStoreConfig::PacStoreStatePasswordRequired) {
       
   264         EapQtValidatorStub *validator = new EapQtValidatorStub(EapQtValidator::StatusOk);
       
   265         setValidatorPacStore(EapQtPacStoreConfig::PacStorePasswordConfirmation, validator);
       
   266     }
       
   267     
       
   268     EapQtConfig config;
       
   269     config.setValue(EapQtConfig::ProvisioningModeAuthenticated, false);
       
   270     config.setValue(EapQtConfig::ProvisioningModeUnauthenticated, true);
       
   271     config.setValue(EapQtConfig::VerifyServerRealm, false);
       
   272     config.setValue(EapQtConfig::UseIdentityPrivacy, false);
       
   273     
       
   274     QList<QVariant> innerTypeList;
       
   275     EapQtPluginHandle inner(EapQtPluginHandle::PluginEapMschapv2);
       
   276     innerTypeList.append(qVariantFromValue(inner));
       
   277     config.setValue(EapQtConfig::InnerType, innerTypeList);
       
   278     
       
   279     setOuterConfig(EapQtPluginHandle::PluginEapFast, config, true);
       
   280 }
       
   281 
       
   282 QStringList EapQtConfigInterfaceContext::calledMethods()
       
   283 {
       
   284     QStringList methods = mEapQtConfig->mCalledMethods;
       
   285     mEapQtConfig->mCalledMethods.clear();
       
   286     return methods;
       
   287 }
       
   288 
       
   289 void EapQtConfigInterfaceContext::setConfigurationReference(
       
   290     int iapId, 
       
   291     bool retValue)
       
   292 {
       
   293     mEapQtConfig->mIapId = iapId;
       
   294     setConfigurationReferenceReturn(retValue);
       
   295 }
       
   296 
       
   297 void EapQtConfigInterfaceContext::setConfigurationReferenceReturn(bool retValue)
       
   298 {
       
   299     mEapQtConfig->mReturnSetConfigurationReference = retValue;    
       
   300 }
       
   301 
       
   302 void EapQtConfigInterfaceContext::setCertsCa(
       
   303     QList<EapQtCertificateInfo> &certs)
       
   304 {
       
   305     mEapQtConfig->mCertsCa = certs;
       
   306 }
       
   307 
       
   308 void EapQtConfigInterfaceContext::setCertsUser(
       
   309     QList<EapQtCertificateInfo> &certs)
       
   310 {
       
   311     mEapQtConfig->mCertsUser = certs;
       
   312 }
       
   313 
       
   314 void EapQtConfigInterfaceContext::setSupportedOuterTypes(
       
   315     QList<EapQtPluginHandle> &outerTypes)
       
   316 {
       
   317     mEapQtConfig->mSupportedOuterTypes = outerTypes;
       
   318 }
       
   319 
       
   320 void EapQtConfigInterfaceContext::setSupportedInnerTypes(
       
   321     EapQtPluginHandle outerHandle, 
       
   322     QList<EapQtPluginHandle> &innerTypes)
       
   323 {
       
   324     mEapQtConfig->mSupportedInnerTypes = innerTypes;
       
   325     mEapQtConfig->mSupportedInnerTypesOuterHandle = outerHandle.pluginId();
       
   326 }
       
   327 
       
   328 void EapQtConfigInterfaceContext::setSelectectedOuterTypes(
       
   329     QList<EapQtPluginHandle> &types,
       
   330     bool retValue)
       
   331 {
       
   332     mEapQtConfig->mSetSelectectedOuterTypes = types;
       
   333     setSelectectedOuterTypesReturn(retValue);
       
   334 }
       
   335 
       
   336 void EapQtConfigInterfaceContext::setSelectectedOuterTypesReturn(bool retValue)
       
   337 {
       
   338     mEapQtConfig->mReturnSetSelectedOuterTypes = retValue;
       
   339 }
       
   340 
       
   341 void EapQtConfigInterfaceContext::setOuterConfig(
       
   342     EapQtPluginHandle::Plugin handle,
       
   343     EapQtConfig &config, 
       
   344     bool retValue)
       
   345 {
       
   346     mEapQtConfig->mOuterPlugin = handle;
       
   347     mEapQtConfig->mSaveConfigurationsOuter = config;
       
   348     setOuterConfigReturn(retValue);
       
   349 }
       
   350 
       
   351 void EapQtConfigInterfaceContext::setOuterConfigReturn(bool retValue)
       
   352 {
       
   353     mEapQtConfig->mReturnSaveConfigurationOuter = retValue;
       
   354 }
       
   355 
       
   356 void EapQtConfigInterfaceContext::setInnerConfig(
       
   357     EapQtPluginHandle::Plugin handle,
       
   358     EapQtConfig &config, 
       
   359     bool retValue)
       
   360 {
       
   361     mEapQtConfig->mInnerPlugin = handle;
       
   362     mEapQtConfig->mSaveConfigurationsInner = config;
       
   363     setInnerConfigReturn(retValue);
       
   364 }
       
   365 
       
   366 void EapQtConfigInterfaceContext::setInnerConfigReturn(bool retValue)
       
   367 {
       
   368     mEapQtConfig->mReturnSaveConfigurationInner = retValue;
       
   369 }
       
   370 
       
   371 void EapQtConfigInterfaceContext::setValidator(
       
   372     EapQtExpandedEapType::Type eapType,
       
   373     EapQtConfig::SettingsId id, 
       
   374     EapQtValidator *validator)
       
   375 {
       
   376     QCOMPARE(mEapQtConfig->mValidator[eapType][id] == NULL, true);
       
   377     mEapQtConfig->mValidator[eapType][id] = validator;
       
   378 }
       
   379 
       
   380 
       
   381 EapQtValidator *EapQtConfigInterfaceContext::validator(
       
   382     EapQtExpandedEapType::Type eapType,
       
   383     EapQtConfig::SettingsId id)
       
   384 {
       
   385     return mEapQtConfig->mValidator[eapType][id];
       
   386 }
       
   387 
       
   388 void EapQtConfigInterfaceContext::setPacStoreConfigRead(
       
   389     EapQtPacStoreConfig &config,
       
   390     bool retValue)
       
   391 {
       
   392     mEapQtConfig->mReadPacStoreConfiguration = config;
       
   393     setPacStoreConfigReadReturn(retValue);
       
   394 }
       
   395 
       
   396 void EapQtConfigInterfaceContext::setPacStoreConfigReadReturn(bool retValue)
       
   397 {
       
   398     mEapQtConfig->mReadPacStoreConfigurationReturn = retValue;
       
   399 }
       
   400 
       
   401 void EapQtConfigInterfaceContext::setPacStoreConfigSave(
       
   402     EapQtPacStoreConfig &config,
       
   403     bool retValue)
       
   404 {
       
   405     mEapQtConfig->mSavePacStoreConfiguration = config;
       
   406     setPacStoreConfigSaveReturn(retValue);
       
   407 }
       
   408 
       
   409 void EapQtConfigInterfaceContext::setPacStoreConfigSaveReturn(bool retValue)
       
   410 {
       
   411     mEapQtConfig->mSavePacStoreConfigurationReturn = retValue;
       
   412 }
       
   413 
       
   414 void EapQtConfigInterfaceContext::setValidatorPacStore(int id, EapQtValidator * validator)
       
   415 {
       
   416     mEapQtConfig->mValidatorPacStore[id] = validator;
       
   417 }
       
   418 
       
   419 EapQtValidator *EapQtConfigInterfaceContext::validatorPacStore(int id)
       
   420 {
       
   421     return mEapQtConfig->mValidatorPacStore[id];
       
   422 }