source: main/trunk/greenstone2/runtime-src/packages/security/gs-code-changes/TestMainWin32.cpp@ 28886

Last change on this file since 28886 was 28886, checked in by ak19, 10 years ago

Additions to the OWASP-for-C++ security package, even though we are no longer using this now. Adding Dr Bainbridge's new files esapitools.cpp and .h, in case we use this in future, along with its Makefile.in. Adding configure files to enable/disable the security package. (The Makefile in runtime-src/packages is not yet complete.)

File size: 3.2 KB
Line 
1/**
2* OWASP Enterprise Security API (ESAPI)
3*
4* This file is part of the Open Web Application Security Project (OWASP)
5* Enterprise Security API (ESAPI) project. For details, please see
6* http://www.owasp.org/index.php/ESAPI.
7*
8* Copyright (c) 2011 - The OWASP Foundation
9*
10* @author Kevin Wall, [email protected]
11* @author Jeffrey Walton, [email protected]
12*
13*/
14
15/////////////////////////////////////////////////////////////
16// Used by Windows. For Linux, Boost::Test provides main() //
17/////////////////////////////////////////////////////////////
18
19#include "EsapiCommon.h"
20using esapi::String;
21using esapi::StringArray;
22using esapi::StringStream;
23using esapi::NarrowString;
24using esapi::WideString;
25
26#include "errors/IllegalArgumentException.h"
27using esapi::IllegalArgumentException;
28
29#include "errors/EncryptionException.h"
30using esapi::EncryptionException;
31
32#include "errors/NoSuchAlgorithmException.h"
33using esapi::NoSuchAlgorithmException;
34
35#include "crypto/SecureRandom.h"
36using esapi::SecureRandom;
37
38#include "crypto/RandomPool.h"
39using esapi::RandomPool;
40
41#include "crypto/KeyGenerator.h"
42using esapi::KeyGenerator;
43
44#include "crypto/PlainText.h"
45using esapi::PlainText;
46
47#include "crypto/CipherText.h"
48using esapi::CipherText;
49
50#include "crypto/SecretKey.h"
51using esapi::SecretKey;
52
53#include "crypto/MessageDigest.h"
54using esapi::MessageDigest;
55
56#include "util/SecureArray.h"
57using esapi::SecureByteArray;
58using esapi::SecureIntArray;
59
60#include "util/SecureString.h"
61using esapi::SecureString;
62
63#include "DummyConfiguration.h"
64using esapi::DummyConfiguration;
65
66#include "reference/DefaultEncryptor.h"
67using esapi::DefaultEncryptor;
68
69#include "util/TextConvert.h"
70using esapi::TextConvert;
71
72#include "util/AlgorithmName.h"
73using esapi::AlgorithmName;
74
75#include "crypto/Cipher.h"
76using esapi::Cipher;
77
78#include "codecs/HTMLEntityCodec.h"
79using esapi::HTMLEntityCodec;
80
81#include <iostream>
82using std::cerr;
83using std::cout;
84using std::endl;
85
86#include <string>
87using std::string;
88
89#include <cstddef>
90#include <memory>
91#include <string>
92
93static const WideString wide = L"\u9aa8";
94static const NarrowString narrow("\xe9\xaa\xa8");
95
96int main(int, char**)
97{
98 // Positive test - uses the overload which takes a 'Char' character
99 HTMLEntityCodec codec;
100
101 struct KnownAnswer
102 {
103 int ch;
104 NarrowString str;
105 };
106
107 // First and last 4 from entity table
108 const KnownAnswer tests[] = {
109 //{ 34, "&quot;" },
110 //{ 38, "&amp;" },
111 //{ 60, "&lt;" },
112 //{ 62, "&gt;" },
113
114 { 252, "&uuml;" },
115 { 253, "&yacute;" },
116 { 254, "&thorn;" },
117 { 255, "&yuml;" }
118 };
119
120 StringArray immune;
121
122 for( unsigned int i = 0; i < COUNTOF(tests); i++ )
123 {
124 const NarrowString utf8 = TextConvert::WideToNarrow(WideString(1,tests[i].ch));
125 const NarrowString encoded = codec.encodeCharacter( immune, utf8 );
126 const NarrowString expected = tests[i].str;
127
128 StringStream oss;
129 oss << "Failed to encode character. Expected ";
130 oss << "'" << expected << "', got ";
131 oss << "'" << encoded << "'";
132
133 if(!(encoded == expected)) {
134 cout << oss.str() << endl;
135 } else {
136 cout << "** WORKED: " << oss.str() << endl;
137 }
138
139 }
140
141 return 0;
142}
Note: See TracBrowser for help on using the repository browser.