aboutsummaryrefslogtreecommitdiffstats
path: root/SoftHSMv2/src/lib/object_store/test/DBObjectTests.cpp
blob: 22d252c0a1d9acc028ee0b1d9ff513dc748560d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
/*
 * Copyright (c) 2013 SURFnet bv
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*****************************************************************************
 DBObjectTests.cpp

 Contains test cases to test the database token object implementation
 *****************************************************************************/

#include <stdlib.h>
#include <string.h>
#include <cppunit/extensions/HelperMacros.h>
#include "DBObjectTests.h"
#include "DBObject.h"

#include <cstdio>

#ifndef HAVE_SQLITE3_H
#error expected sqlite3 to be available
#endif

CPPUNIT_TEST_SUITE_REGISTRATION(test_a_dbobject);

void test_a_dbobject::setUp()
{
	CPPUNIT_ASSERT(!system("mkdir testdir"));
	connection = DB::Connection::Create("testdir","TestToken");
	CPPUNIT_ASSERT(connection != NULL);
	CPPUNIT_ASSERT(connection->connect("<1>"));
	connection->setBusyTimeout(10);

	DBObject testObject(connection);
	CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));
	CPPUNIT_ASSERT(testObject.createTables());
	CPPUNIT_ASSERT(testObject.commitTransaction());

	connection2 = DB::Connection::Create("testdir","TestToken");
	CPPUNIT_ASSERT(connection2 != NULL);
	CPPUNIT_ASSERT(connection2->connect("<2>"));
	connection2->setBusyTimeout(10);
}

void test_a_dbobject::tearDown()
{
	CPPUNIT_ASSERT(connection != NULL);
	connection->close();
	delete connection;

	CPPUNIT_ASSERT(connection2 != NULL);
	connection2->close();
	delete connection2;

#ifndef _WIN32
	CPPUNIT_ASSERT(!system("rm -rf testdir"));
#else
	CPPUNIT_ASSERT(!system("rmdir /s /q testdir 2> nul"));
#endif
}

void test_a_dbobject::should_be_insertable()
{
	DBObject tokenObject(connection);
	CPPUNIT_ASSERT(!tokenObject.isValid());
	CPPUNIT_ASSERT(tokenObject.insert());
	CPPUNIT_ASSERT(tokenObject.isValid());
	CPPUNIT_ASSERT_EQUAL(tokenObject.objectId(), (long long)1);
}

void test_a_dbobject::should_be_selectable()
{
	should_be_insertable();

	DBObject tokenObject(connection);
	CPPUNIT_ASSERT(tokenObject.find(1));
	CPPUNIT_ASSERT(tokenObject.isValid());
}

CPPUNIT_TEST_SUITE_REGISTRATION(test_a_dbobject_with_an_object);

void test_a_dbobject_with_an_object::setUp()
{
	test_a_dbobject::setUp();
	DBObject tokenObject(connection);
	CPPUNIT_ASSERT(tokenObject.startTransaction(DBObject::ReadWrite));
	CPPUNIT_ASSERT(!tokenObject.isValid());
	CPPUNIT_ASSERT(tokenObject.insert());
	CPPUNIT_ASSERT(tokenObject.isValid());
	CPPUNIT_ASSERT_EQUAL(tokenObject.objectId(), (long long)1);
	CPPUNIT_ASSERT(tokenObject.commitTransaction());

}

void test_a_dbobject_with_an_object::tearDown()
{
	test_a_dbobject::tearDown();
}

void test_a_dbobject_with_an_object::should_store_boolean_attributes()
{
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		bool value1 = true;
		bool value2 = false;
		bool value3 = true;
		bool value4 = true;
		bool value5 = false;

		OSAttribute attr1(value1);
		OSAttribute attr2(value2);
		OSAttribute attr3(value3);
		OSAttribute attr4(value4);
		OSAttribute attr5(value5);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SENSITIVE, attr2));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_EXTRACTABLE, attr3));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_NEVER_EXTRACTABLE, attr4));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SIGN, attr5));
	}

	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_TOKEN));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SENSITIVE));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_EXTRACTABLE));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_NEVER_EXTRACTABLE));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SIGN));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SENSITIVE).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_EXTRACTABLE).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_NEVER_EXTRACTABLE).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).isBooleanAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue());
		CPPUNIT_ASSERT(!testObject.getAttribute(CKA_SENSITIVE).getBooleanValue());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_EXTRACTABLE).getBooleanValue());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_NEVER_EXTRACTABLE).getBooleanValue());
		CPPUNIT_ASSERT(!testObject.getAttribute(CKA_SIGN).getBooleanValue());

		bool value6 = true;
		OSAttribute attr6(value6);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_VERIFY, attr6));
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_VERIFY).isBooleanAttribute());
		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_VERIFY).getBooleanValue(), value6);
		CPPUNIT_ASSERT_EQUAL(testObject.getBooleanValue(CKA_VERIFY, false), value6);
	}
}


void test_a_dbobject_with_an_object::should_store_unsigned_long_attributes()
{
	// Add unsigned long attributes to the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		unsigned long value1 = 0x12345678;
		unsigned long value2 = 0x87654321;
		unsigned long value3 = 0x01010101;
		unsigned long value4 = 0x10101010;
		unsigned long value5 = 0xABCDEF;

		OSAttribute attr1(value1);
		OSAttribute attr2(value2);
		OSAttribute attr3(value3);
		OSAttribute attr4(value4);
		OSAttribute attr5(value5);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_MODULUS_BITS, attr1));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_AUTH_PIN_FLAGS, attr3));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUB_PRIME_BITS, attr4));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_KEY_TYPE, attr5));
	}

	// Now read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_MODULUS_BITS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_AUTH_PIN_FLAGS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUB_PRIME_BITS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_KEY_TYPE));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUB_PRIME_BITS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE).isUnsignedLongAttribute());

		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_MODULUS_BITS).getUnsignedLongValue(), (unsigned long)0x12345678);
		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue(), (unsigned long)0x87654321);
		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).getUnsignedLongValue(), (unsigned long)0x01010101);
		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_SUB_PRIME_BITS).getUnsignedLongValue(), (unsigned long)0x10101010);
		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_KEY_TYPE).getUnsignedLongValue(), (unsigned long)0xABCDEF);

		unsigned long value6 = 0x90909090;
		OSAttribute attr6(value6);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_CLASS, attr6));
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_CLASS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_CLASS).getUnsignedLongValue(), value6);
		CPPUNIT_ASSERT_EQUAL(testObject.getUnsignedLongValue(CKA_CLASS, 0x0), value6);
	}
}

void test_a_dbobject_with_an_object::should_store_binary_attributes()
{
	ByteString value1 = "010203040506070809";
	ByteString value2 = "ABABABABABABABABABABABABABABABABAB";
	unsigned long value3 = 0xBDED;
	ByteString value4 = "98A7E5D798A7E5D798A7E5D798A7E5D798A7E5D798A7E5D7";
	ByteString value5 = "ABCDABCDABCDABCDABCDABCDABCDABCD";

	// Create the test object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		OSAttribute attr1(value1);
		OSAttribute attr2(value2);
		OSAttribute attr3(value3);
		OSAttribute attr4(value4);
		OSAttribute attr5(value5);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_MODULUS, attr1));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_COEFFICIENT, attr2));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_PUBLIC_EXPONENT, attr4));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBJECT, attr5));
	}

	// Now read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_MODULUS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_COEFFICIENT));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_VALUE_BITS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_PUBLIC_EXPONENT));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUBJECT));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_COEFFICIENT).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_PUBLIC_EXPONENT).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT).isByteStringAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS).getByteStringValue() == value1);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_COEFFICIENT).getByteStringValue() == value2);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_PUBLIC_EXPONENT).getByteStringValue() == value4);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT).getByteStringValue() == value5);

		ByteString value6 = "909090908080808080807070707070FF";
		OSAttribute attr6(value6);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_ISSUER, attr6));
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ISSUER).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject.getByteStringValue(CKA_ISSUER) == value6);
	}
}

void test_a_dbobject_with_an_object::should_store_mechtypeset_attributes()
{

	// Create the test object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		std::set<CK_MECHANISM_TYPE> set;
		set.insert(CKM_SHA256);
		set.insert(CKM_SHA512);
		OSAttribute attr(set);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_ALLOWED_MECHANISMS, attr));
	}

	// Now read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_ALLOWED_MECHANISMS));
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

		std::set<CK_MECHANISM_TYPE> retrieved =
				testObject.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue();

		CPPUNIT_ASSERT(retrieved.size() == 2);
		CPPUNIT_ASSERT(retrieved.find(CKM_SHA256) != retrieved.end());
		CPPUNIT_ASSERT(retrieved.find(CKM_SHA384) == retrieved.end());
		CPPUNIT_ASSERT(retrieved.find(CKM_SHA512) != retrieved.end());
	}
}

void test_a_dbobject_with_an_object::should_store_attrmap_attributes()
{
	bool value1 = true;
	unsigned long value2 = 0x87654321;
	ByteString value3 = "BDEBDBEDBBDBEBDEBE792759537328";
	std::set<CK_MECHANISM_TYPE> value4;
	value4.insert(CKM_SHA256);
	value4.insert(CKM_SHA512);

	// Create the test object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		OSAttribute attr1(value1);
		OSAttribute attr2(value2);
		OSAttribute attr3(value3);
		OSAttribute attr4(value4);

		std::map<CK_ATTRIBUTE_TYPE,OSAttribute> mattr;
		mattr.insert(std::pair<CK_ATTRIBUTE_TYPE,OSAttribute> (CKA_TOKEN, attr1));
		mattr.insert(std::pair<CK_ATTRIBUTE_TYPE,OSAttribute> (CKA_PRIME_BITS, attr2));
		mattr.insert(std::pair<CK_ATTRIBUTE_TYPE,OSAttribute> (CKA_VALUE, attr3));
		mattr.insert(std::pair<CK_ATTRIBUTE_TYPE,OSAttribute> (CKA_ALLOWED_MECHANISMS, attr4));
		OSAttribute attra(mattr);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_WRAP_TEMPLATE, attra));
	}

	// Now read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_WRAP_TEMPLATE));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_UNWRAP_TEMPLATE));

		std::map<CK_ATTRIBUTE_TYPE,OSAttribute> mattrb =
				testObject.getAttribute(CKA_WRAP_TEMPLATE).getAttributeMapValue();
		CPPUNIT_ASSERT(mattrb.size() == 4);
		CPPUNIT_ASSERT(mattrb.find(CKA_TOKEN) != mattrb.end());
		CPPUNIT_ASSERT(mattrb.at(CKA_TOKEN).isBooleanAttribute());
		CPPUNIT_ASSERT(mattrb.at(CKA_TOKEN).getBooleanValue() == true);
		CPPUNIT_ASSERT(mattrb.find(CKA_PRIME_BITS) != mattrb.end());
		CPPUNIT_ASSERT(mattrb.at(CKA_PRIME_BITS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(mattrb.at(CKA_PRIME_BITS).getUnsignedLongValue() == 0x87654321);
		CPPUNIT_ASSERT(mattrb.find(CKA_VALUE) != mattrb.end());
		CPPUNIT_ASSERT(mattrb.at(CKA_VALUE).isByteStringAttribute());
		CPPUNIT_ASSERT(mattrb.at(CKA_VALUE).getByteStringValue() == value3);
		CPPUNIT_ASSERT(mattrb.find(CKA_ALLOWED_MECHANISMS) != mattrb.end());
		CPPUNIT_ASSERT(mattrb.at(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());
		CPPUNIT_ASSERT(mattrb.at(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value4);
	}
}

void test_a_dbobject_with_an_object::should_store_mixed_attributes()
{
	bool value1 = true;
	unsigned long value2 = 0x87654321;
	unsigned long value3 = 0xBDEBDBED;
	std::set<CK_MECHANISM_TYPE> value4;
	value4.insert(CKM_SHA256);
	value4.insert(CKM_SHA512);

	// Create the test object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		OSAttribute attr1(value1);
		OSAttribute attr2(value2);
		OSAttribute attr3(value3);
		OSAttribute attr4(value4);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_ALLOWED_MECHANISMS, attr4));
	}

	// Now read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_TOKEN));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_VALUE_BITS));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_ALLOWED_MECHANISMS));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue());
		CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue(), value2);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value4);
	}
}

void test_a_dbobject_with_an_object::should_store_double_attributes()
{
	bool value1 = true;
	bool value1a = false;

	// Create the test object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		OSAttribute attr1(value1);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SIGN, attr1));
	}

	// Now read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SIGN));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).isBooleanAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).getBooleanValue());

		OSAttribute attr1(value1a);

		// Change the attributes
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SIGN, attr1));

		// Check the attributes
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).isBooleanAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).getBooleanValue() == value1a);
	}

	// Now re-read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SIGN));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).isBooleanAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).getBooleanValue() == value1a);
	}
}

void test_a_dbobject_with_an_object::can_refresh_attributes()
{
	bool value1 = true;
	bool value1a = false;
	ByteString value2 = "BDEBDBEDBBDBEBDEBE792759537328";
	ByteString value2a = "466487346943785684957634";
	ByteString value3 = "0102010201020102010201020102010201020102";
	std::set<CK_MECHANISM_TYPE> value4;
	value4.insert(CKM_SHA256);
	value4.insert(CKM_SHA512);
	std::set<CK_MECHANISM_TYPE> value4a;
	value4a.insert(CKM_SHA384);
	value4a.insert(CKM_SHA512);

	// Create the test object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		OSAttribute attr1(value1);
		OSAttribute attr2(value2);
		OSAttribute attr4(value4);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SIGN, attr1));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBJECT, attr2));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_ALLOWED_MECHANISMS, attr4));
	}

	// Now read back the object
	{
		DBObject testObject(connection);
		CPPUNIT_ASSERT(testObject.find(1));
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SIGN));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUBJECT));
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_ALLOWED_MECHANISMS));
		CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).getBooleanValue());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT).getByteStringValue() == value2);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value4);

		OSAttribute attr1(value1a);
		OSAttribute attr2(value2a);
		OSAttribute attr4(value4a);

		// Change the attributes
		CPPUNIT_ASSERT(testObject.isValid());

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SIGN, attr1));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBJECT, attr2));
		CPPUNIT_ASSERT(testObject.setAttribute(CKA_ALLOWED_MECHANISMS, attr4));

		// Check the attributes
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN).getBooleanValue() == value1a);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT).getByteStringValue() == value2a);
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value4a);

		// Open the object a second time
		DBObject testObject2(connection);
		CPPUNIT_ASSERT(testObject2.find(1));
		CPPUNIT_ASSERT(testObject2.isValid());

		// Check the attributes on the second instance
		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_SIGN).isBooleanAttribute());
		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_SUBJECT).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_SIGN).getBooleanValue() == value1a);
		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_SUBJECT).getByteStringValue() == value2a);
		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value4a);

		// Add an attribute on the second object
		OSAttribute attr3(value3);

		CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr3));

		// Check the attribute
		CPPUNIT_ASSERT(testObject2.attributeExists(CKA_ID));
		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value3);

		// Now check that the first instance also knows about it
		CPPUNIT_ASSERT(testObject.attributeExists(CKA_ID));
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());
		CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value3);
	}
}

void test_a_dbobject_with_an_object::should_cleanup_statements_during_transactions()
{
	// Create an object for accessing object 1 on the first connection.
	DBObject testObject(connection);
	// check transaction start(ro)/abort sequence
	CPPUNIT_ASSERT(testObject.startTransaction(OSObject::ReadOnly));
	CPPUNIT_ASSERT(testObject.find(1));
	CPPUNIT_ASSERT(testObject.isValid());
	CPPUNIT_ASSERT(testObject.abortTransaction());
}

void test_a_dbobject_with_an_object::should_use_transactions()
{
	DBObject testObject(connection);
	CPPUNIT_ASSERT(testObject.find(1));
	CPPUNIT_ASSERT(testObject.isValid());

	bool value1 = true;
	unsigned long value2 = 0x87654321;
	unsigned long value3 = 0xBDEBDBED;
	ByteString value4 = "AAAAAAAAAAAAAAAFFFFFFFFFFFFFFF";
	std::set<CK_MECHANISM_TYPE> value5;
	value5.insert(CKM_SHA256);
	value5.insert(CKM_SHA512);

	OSAttribute attr1(value1);
	OSAttribute attr2(value2);
	OSAttribute attr3(value3);
	OSAttribute attr4(value4);
	OSAttribute attr5(value5);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_ALLOWED_MECHANISMS, attr5));

	// Create secondary instance for the same object.
	// This needs to have a different connection to the database to simulate
	// another process accessing the data.
	DBObject testObject2(connection2);
	CPPUNIT_ASSERT(testObject2.find(1));
	CPPUNIT_ASSERT(testObject2.isValid());

	// Check that it has the same attributes
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	// Check that the attributes have the same values as set on testObject.
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value5);

	// New values
	bool value1a = false;
	unsigned long value2a = 0x12345678;
	unsigned long value3a = 0xABABABAB;
	ByteString value4a = "EDEDEDEDEDEDEDEDEDEDEDEDEDEDED";
	std::set<CK_MECHANISM_TYPE> value5a;
	value5a.insert(CKM_SHA384);
	value5a.insert(CKM_SHA512);

	OSAttribute attr1a(value1a);
	OSAttribute attr2a(value2a);
	OSAttribute attr3a(value3a);
	OSAttribute attr4a(value4a);
	OSAttribute attr5a(value5a);

	// Start transaction on object
	CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));

	// Change the attributes
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1a));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2a));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3a));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4a));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_ALLOWED_MECHANISMS, attr5a));

	// Verify that the attributes were set
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value5a);

	// Verify that they are unchanged on the other instance
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value5);

	// Commit the transaction
	CPPUNIT_ASSERT(testObject.commitTransaction());

	// Verify that non-modifiable attributes did not propagate but modifiable attributes
	// have now changed on the other instance
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	// NOTE: 3 attributes below cannot be modified after creation and therefore are not required to propagate.
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() != value1a);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() != value2a);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() != value3a);
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() != value5a);

	// CKA_ID attribute can be modified after creation and therefore should have propagated.
	CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4a);

	// Start transaction on object
	CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));

	// Change the attributes
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_ALLOWED_MECHANISMS, attr5));

	// Verify that the attributes were set
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value5);

	// Create a fresh third instance for the same object to force the data to be retrieved from the database.
	DBObject testObject3(connection2);
	CPPUNIT_ASSERT(testObject3.find(1));
	CPPUNIT_ASSERT(testObject3.isValid());

	// Verify that they are unchanged on the other instance, while the transaction is still in progress.
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	// Verify that the attributes from the database are still hodling the same value as when the transaction started.
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).getByteStringValue() == value4a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value5a);

	// Abort the transaction
	CPPUNIT_ASSERT(testObject.abortTransaction());

	// Verify that after aborting the transaction the values in testObject have reverted back to their
	// original state.
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	// After aborting a transaction the testObject should be back to pre transaction state.
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value5a);

	// Verify that testObject3 still has the original values.
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).isBooleanAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).isByteStringAttribute());
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ALLOWED_MECHANISMS).isMechanismTypeSetAttribute());

	// Verify that testObject3 still has the original values.
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).getByteStringValue() == value4a);
	CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ALLOWED_MECHANISMS).getMechanismTypeSetValue() == value5a);
}

void test_a_dbobject_with_an_object::should_fail_to_delete()
{
	DBObject testObject(connection);
	CPPUNIT_ASSERT(testObject.find(1));
	CPPUNIT_ASSERT(testObject.isValid());
	// We don't attach the object to a token, and therefore should not be able to destroy it.
	CPPUNIT_ASSERT(!testObject.destroyObject());
}