- added and tested auth_payload_t class
[strongswan.git] / Source / charon / testcases / generator_test.c
index b3faa99..d53a8e7 100644 (file)
@@ -39,6 +39,7 @@
 #include <encoding/payloads/notify_payload.h>
 #include <encoding/payloads/nonce_payload.h>
 #include <encoding/payloads/id_payload.h>
+#include <encoding/payloads/auth_payload.h>
 
 /*
  * Described in Header 
@@ -785,3 +786,55 @@ void test_generator_with_id_payload(tester_t *tester)
        charon->logger_manager->destroy_logger(charon->logger_manager,logger);  
 }
 
+/*
+ * Described in header.
+ */ 
+void test_generator_with_auth_payload(tester_t *tester)
+{
+       generator_t *generator;
+       auth_payload_t *auth_payload;
+       logger_t *logger;
+       chunk_t generated_data;
+       chunk_t auth;
+       
+       logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with AUTH Payload");
+       
+       /* create generator */
+       generator = generator_create();
+       tester->assert_true(tester,(generator != NULL), "generator create check");
+       
+       auth_payload = auth_payload_create(FALSE);
+       
+       
+       auth.ptr = "123456789012";
+       auth.len = strlen(auth.ptr);
+
+       auth_payload->set_auth_method(auth_payload,SHARED_KEY_MESSAGE_INTEGRITY_CODE);
+       auth_payload->set_data(auth_payload,auth);
+       
+       generator->generate_payload(generator,(payload_t *)auth_payload);
+       generator->write_to_chunk(generator,&generated_data);
+       logger->log_chunk(logger,RAW,"generated payload",&generated_data);      
+       
+
+       u_int8_t expected_generation[] = {
+               /* payload header */
+               0x00,0x00,0x00,0x14,
+               0x02,0x00,0x00,0x00,
+               /* auth data */
+               0x31,0x32,0x33,0x34,
+               0x35,0x36,0x37,0x38,
+               0x39,0x30,0x31,0x32,
+       };
+       
+       logger->log_bytes(logger,RAW,"expected payload",expected_generation,sizeof(expected_generation));       
+       
+       tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
+
+       allocator_free_chunk(&generated_data);
+       
+       auth_payload->destroy(auth_payload);
+       generator->destroy(generator);
+               
+       charon->logger_manager->destroy_logger(charon->logger_manager,logger);  
+}