20
20
-module(base64_SUITE).
21
-author('jakob@erix.ericsson.se').
23
-include("test_server.hrl").
22
-include_lib("common_test/include/ct.hrl").
24
23
-include("test_server_line.hrl").
26
25
%% Test server specific exports
27
-export([all/1, init_per_testcase/2, end_per_testcase/2]).
26
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
27
init_per_group/2,end_per_group/2,
28
init_per_testcase/2, end_per_testcase/2]).
29
30
%% Test cases must be exported.
30
31
-export([base64_encode/1, base64_decode/1, base64_otp_5635/1,
31
32
base64_otp_6279/1, big/1, illegal/1, mime_decode/1,
33
mime_decode_to_string/1, roundtrip/1]).
34
35
init_per_testcase(_, Config) ->
35
36
Dog = test_server:timetrap(?t:minutes(2)),
44
45
%%-------------------------------------------------------------------------
45
46
%% Test cases starts here.
46
47
%%-------------------------------------------------------------------------
48
["Test library functions for base64 encode and decode "
49
"(taken from inets/test/http_format_SUITE)"];
48
suite() -> [{ct_hooks,[ts_install_cth]}].
51
51
[base64_encode, base64_decode, base64_otp_5635,
52
base64_otp_6279, big, illegal, mime_decode,
52
base64_otp_6279, big, illegal, mime_decode, mime_decode_to_string,
58
init_per_suite(Config) ->
61
end_per_suite(_Config) ->
64
init_per_group(_GroupName, Config) ->
67
end_per_group(_GroupName, Config) ->
56
72
%%-------------------------------------------------------------------------
57
73
base64_encode(doc) ->
138
154
{'EXIT',{function_clause, _}} = (catch base64:decode("()")),
140
156
%%-------------------------------------------------------------------------
157
%% mime_decode and mime_decode_to_string have different implementations
158
%% so test both with the same input separately. Both functions have
159
%% the same implementation for binary/string arguments.
141
160
mime_decode(doc) ->
142
161
["Test base64:mime_decode/1."];
143
162
mime_decode(suite) ->
145
164
mime_decode(Config) when is_list(Config) ->
147
<<"Aladdin:open sesame">> =
165
%% Test correct padding
166
<<"one">> = base64:mime_decode(<<"b25l">>),
167
<<"on">> = base64:mime_decode(<<"b24=">>),
168
<<"o">> = base64:mime_decode(<<"bw==">>),
169
%% Test 1 extra padding
170
<<"one">> = base64:mime_decode(<<"b25l= =">>),
171
<<"on">> = base64:mime_decode(<<"b24== =">>),
172
<<"o">> = base64:mime_decode(<<"bw=== =">>),
173
%% Test 2 extra padding
174
<<"one">> = base64:mime_decode(<<"b25l===">>),
175
<<"on">> = base64:mime_decode(<<"b24====">>),
176
<<"o">> = base64:mime_decode(<<"bw=====">>),
177
%% Test misc embedded padding
178
<<"one">> = base64:mime_decode(<<"b2=5l===">>),
179
<<"on">> = base64:mime_decode(<<"b=24====">>),
180
<<"o">> = base64:mime_decode(<<"b=w=====">>),
181
%% Test misc white space and illegals with embedded padding
182
<<"one">> = base64:mime_decode(<<" b~2=\r\n5()l===">>),
183
<<"on">> = base64:mime_decode(<<"\tb =2\"�4=�= ==">>),
184
<<"o">> = base64:mime_decode(<<"\nb=w=====">>),
186
<<"Aladdin:open sesame">> =
148
187
base64:mime_decode("QWxhZGRpbjpvc()GVuIHNlc2FtZQ=="),
149
%% One pad, followed by ignored text
150
<<"Hello World">> = base64:mime_decode(<<"SGVsb)(G8gV29ybGQ=apa">>),
188
%% One pad to ignore, followed by more text
189
<<"Hello World!!">> = base64:mime_decode(<<"SGVsb)(G8gV29ybGQ=h IQ= =">>),
191
<<"Aladdin:open sesam">> =
192
base64:mime_decode("QWxhZGRpbjpvcG�\")(VuIHNlc2Ft"),
193
%% Encoded base 64 strings may be divided by non base 64 chars.
194
%% In this cases whitespaces.
195
<<"0123456789!@#0^&*();:<>,. []{}">> =
197
<<"MDEy MzQ1Njc4 \tOSFAIzBeJ \nio)(oKTs6 PD4sLi \r\nBbXXt9">>),
200
%%-------------------------------------------------------------------------
202
%% Repeat of mime_decode() tests
203
mime_decode_to_string(doc) ->
204
["Test base64:mime_decode_to_string/1."];
205
mime_decode_to_string(suite) ->
207
mime_decode_to_string(Config) when is_list(Config) ->
208
%% Test correct padding
209
"one" = base64:mime_decode_to_string(<<"b25l">>),
210
"on" = base64:mime_decode_to_string(<<"b24=">>),
211
"o" = base64:mime_decode_to_string(<<"bw==">>),
212
%% Test 1 extra padding
213
"one" = base64:mime_decode_to_string(<<"b25l= =">>),
214
"on" = base64:mime_decode_to_string(<<"b24== =">>),
215
"o" = base64:mime_decode_to_string(<<"bw=== =">>),
216
%% Test 2 extra padding
217
"one" = base64:mime_decode_to_string(<<"b25l===">>),
218
"on" = base64:mime_decode_to_string(<<"b24====">>),
219
"o" = base64:mime_decode_to_string(<<"bw=====">>),
220
%% Test misc embedded padding
221
"one" = base64:mime_decode_to_string(<<"b2=5l===">>),
222
"on" = base64:mime_decode_to_string(<<"b=24====">>),
223
"o" = base64:mime_decode_to_string(<<"b=w=====">>),
224
%% Test misc white space and illegals with embedded padding
225
"one" = base64:mime_decode_to_string(<<" b~2=\r\n5()l===">>),
226
"on" = base64:mime_decode_to_string(<<"\tb =2\"�4=�= ==">>),
227
"o" = base64:mime_decode_to_string(<<"\nb=w=====">>),
229
"Aladdin:open sesame" =
230
base64:mime_decode_to_string("QWxhZGRpbjpvc()GVuIHNlc2FtZQ=="),
231
%% One pad to ignore, followed by more text
232
"Hello World!!" = base64:mime_decode_to_string(<<"SGVsb)(G8gV29ybGQ=h IQ= =">>),
152
234
"Aladdin:open sesam" =
153
235
base64:mime_decode_to_string("QWxhZGRpbjpvcG�\")(VuIHNlc2Ft"),
155
236
%% Encoded base 64 strings may be divided by non base 64 chars.
156
237
%% In this cases whitespaces.
157
238
"0123456789!@#0^&*();:<>,. []{}" =