コード例 #1
0
/**
@SYMTestCaseID			SYSLIB-SQL-CT-1635
@SYMTestCaseDesc		RSqlSecurityPolicy test.
						Tests RSqlSecurityPolicy API.
@SYMTestPriority		High
@SYMTestActions			RSqlSecurityPolicy test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5792
                        REQ5793
*/
void SqlSecurityPolicyTest()
{
    RSqlSecurityPolicy securityPolicy;
    TInt err = securityPolicy.Create(KDefaultPolicy);
    TEST2(err, KErrNone);

    //Empty RSqlSecurityPolicy object tests
    //Database policies
    TSecurityPolicy policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::ESchemaPolicy);
    TEST(policy == KDefaultPolicy);
    policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KDefaultPolicy);
    policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KDefaultPolicy);
    //Table policies
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, _L("A-Tbl"), RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KDefaultPolicy);
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, _L("B-Tbl"), RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KDefaultPolicy);
    //
    securityPolicy.Close();

    //Tests with initialized RSqlSecurityPolicy object
    CreateTestSecurityPolicy(securityPolicy);
    //Check the created and initialized object
    CheckTestSecurityPolicy(securityPolicy);

    //Externalize, then internalize and check the security policy object
    RFileWriteStream out;
    err = out.Replace(TheFs, KTestFile, EFileRead | EFileWrite);
    TEST2(err, KErrNone);
    TRAP(err, securityPolicy.ExternalizeL(out));
    TEST2(err, KErrNone);
    TRAP(err, out.CommitL());
    out.Close();
    TEST2(err, KErrNone);

    securityPolicy.Close();
    err = securityPolicy.Create(KDefaultPolicy);
    TEST2(err, KErrNone);
    RFileReadStream in;
    err = in.Open(TheFs, KTestFile, EFileRead);
    TEST2(err, KErrNone);
    TRAP(err, securityPolicy.InternalizeL(in));
    in.Close();
    TEST2(err, KErrNone);
    CheckTestSecurityPolicy(securityPolicy);

    //Change some security policies and check that the RqlSecurityPolicy content was properly updated
    err = securityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EReadPolicy, KPolicy3);
    TEST2(err, KErrNone);
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KPolicy3);
    policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KPolicy2);
    //
    securityPolicy.Close();
}
コード例 #2
0
void CheckTestSecurityPolicy(const RSqlSecurityPolicy& aSecurityPolicy)
{
    //Database policies
    TSecurityPolicy policy = aSecurityPolicy.DbPolicy(RSqlSecurityPolicy::ESchemaPolicy);
    TEST(policy == KPolicy1);
    policy = aSecurityPolicy.DbPolicy(RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KDefaultPolicy);
    policy = aSecurityPolicy.DbPolicy(RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KPolicy3);
    //Table  policies
    policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KPolicy1);
    policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KPolicy1);
    policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EReadPolicy);
    TEST(policy == KPolicy2);
    policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KPolicy2);
    policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KPolicy3);
    policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EWritePolicy);
    TEST(policy == KPolicy1);
}