Skip to content

Commit

Permalink
Add codec testcase for decode of unknown AVPs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders Svensson committed Dec 16, 2011
1 parent a2b669f commit 859d947
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lib/diameter/test/Makefile
Expand Up @@ -50,6 +50,8 @@ TARGET_FILES = $(MODULES:%=%.$(EMULATOR))
SUITE_MODULES = $(filter diameter_%_SUITE, $(MODULES))
SUITES = $(SUITE_MODULES:diameter_%_SUITE=%)

DATA_DIRS = $(sort $(dir $(DATA)))

# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
Expand Down Expand Up @@ -147,22 +149,26 @@ else
include $(ERL_TOP)/make/otp_release_targets.mk
endif

release_spec:

release_docs_spec:
release_spec release_docs_spec:

release_tests_spec:
$(INSTALL_DIR) $(RELSYSDIR)
$(INSTALL_DATA) $(TEST_SPEC_FILE) \
$(COVER_SPEC_FILE) \
$(HRL_FILES) \
$(RELSYSDIR)
$(MAKE) $(DATA_DIRS:%/=release_data_%)
$(MAKE) $(ERL_FILES:%=/%)

$(DATA_DIRS:%/=release_data_%): release_data_%:
$(INSTALL_DIR) $(RELSYSDIR)/$*
$(INSTALL_DATA) $(filter $*/%, $(DATA)) $(RELSYSDIR)/$*

force:

.PHONY: release_spec release_docs_spec release_test_specs
.PHONY: force
.PHONY: $(DATA_DIRS:%/=release_data_%)

# Can't just make $(ERL_FILES:%=/%) phony since then implicit rule
# searching is skipped.
Expand Down
28 changes: 26 additions & 2 deletions lib/diameter/test/diameter_codec_SUITE.erl
Expand Up @@ -35,7 +35,8 @@
%% testcases
-export([base/1,
gen/1,
lib/1]).
lib/1,
unknown/1]).

-include("diameter_ct.hrl").

Expand All @@ -47,7 +48,7 @@ suite() ->
[{timetrap, {seconds, 10}}].

all() ->
[base, gen, lib].
[base, gen, lib, unknown].

init_per_testcase(gen, Config) ->
[{application, ?APP, App}] = diameter_util:consult(?APP, app),
Expand All @@ -74,3 +75,26 @@ gen([{dicts, Ms} | _]) ->

lib(_Config) ->
diameter_codec_test:lib().

%% Have a separate AVP dictionary just to exercise more code.
unknown(Config) ->
Priv = proplists:get_value(priv_dir, Config),
Data = proplists:get_value(data_dir, Config),
ok = make(Data, "recv.dia"),
ok = make(Data, "avps.dia"),
{ok, _, _} = compile("diameter_test_avps.erl"),
ok = make(Data, "send.dia"),
{ok, _, _} = compile("diameter_test_send.erl"),
{ok, _, _} = compile("diameter_test_recv.erl"),
{ok, _, _} = compile(filename:join([Data, "diameter_test_unknown.erl"]),
[{i, Priv}]),
diameter_test_unknown:run().

make(Dir, File) ->
diameter_make:codec(filename:join([Dir, File])).

compile(File) ->
compile(File, []).

compile(File, Opts) ->
compile:file(File, [return | Opts]).
25 changes: 25 additions & 0 deletions lib/diameter/test/diameter_codec_SUITE_data/avps.dia
@@ -0,0 +1,25 @@
;;
;; %CopyrightBegin%
;;
;; Copyright Ericsson AB 2010-2011. All Rights Reserved.
;;
;; The contents of this file are subject to the Erlang Public License,
;; Version 1.1, (the "License"); you may not use this file except in
;; compliance with the License. You should have received a copy of the
;; Erlang Public License along with this software. If not, it can be
;; retrieved online at http://www.erlang.org/.
;;
;; Software distributed under the License is distributed on an "AS IS"
;; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
;; the License for the specific language governing rights and limitations
;; under the License.
;;
;; %CopyrightEnd%
;;

@name diameter_test_avps

@avp_types

XXX 111 Unsigned32 M
YYY 222 Unsigned32 -
@@ -0,0 +1,76 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%

-module(diameter_test_unknown).

-compile(export_all).

%%
%% Test reception of unknown AVP's.
%%

-include_lib("diameter/include/diameter.hrl").
-include("diameter_test_send.hrl").
-include("diameter_test_recv.hrl").

-define(HOST, "test.erlang.org").
-define(REALM, "erlang.org").

%% Patterns to match decoded AVP's.
-define(MANDATORY_XXX, #diameter_avp{code = 111}).
-define(NOT_MANDATORY_YYY, #diameter_avp{code = 222}).

%% Ensure that an unknown AVP with an M flag is regarded as an error
%% while one without an M flag is returned as 'AVP'.

run() ->
H = #diameter_header{version = 1,
end_to_end_id = 1,
hop_by_hop_id = 1},
Vs = [{'Origin-Host', ?HOST},
{'Origin-Realm', ?REALM},
{'XXX', [0]},
{'YYY', [1]}],
Pkt = #diameter_packet{header = H,
msg = Vs},

[] = diameter_util:run([{?MODULE, [run, M, enc(M, Pkt)]}
|| M <- ['AR','BR']]).

enc(M, #diameter_packet{msg = Vs} = P) ->
diameter_codec:encode(diameter_test_send,
P#diameter_packet{msg = [M|Vs]}).

run(M, Pkt) ->
dec(M, diameter_codec:decode(diameter_test_recv, Pkt)).
%% Note that the recv dictionary defines neither XXX nor YYY.

dec('AR', #diameter_packet
{msg = #recv_AR{'Origin-Host' = ?HOST,
'Origin-Realm' = ?REALM,
'AVP' = [?NOT_MANDATORY_YYY]},
errors = [{5001, ?MANDATORY_XXX}]}) ->
ok;

dec('BR', #diameter_packet
{msg = #recv_BR{'Origin-Host' = ?HOST,
'Origin-Realm' = ?REALM},
errors = [{5008, ?NOT_MANDATORY_YYY},
{5001, ?MANDATORY_XXX}]}) ->
ok.
51 changes: 51 additions & 0 deletions lib/diameter/test/diameter_codec_SUITE_data/recv.dia
@@ -0,0 +1,51 @@
;;
;; %CopyrightBegin%
;;
;; Copyright Ericsson AB 2010-2011. All Rights Reserved.
;;
;; The contents of this file are subject to the Erlang Public License,
;; Version 1.1, (the "License"); you may not use this file except in
;; compliance with the License. You should have received a copy of the
;; Erlang Public License along with this software. If not, it can be
;; retrieved online at http://www.erlang.org/.
;;
;; Software distributed under the License is distributed on an "AS IS"
;; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
;; the License for the specific language governing rights and limitations
;; under the License.
;;
;; %CopyrightEnd%
;;

@id 17
@name diameter_test_recv
@prefix recv

@inherits diameter_gen_base_rfc3588

Origin-Host
Origin-Realm
Result-Code

@messages

AR ::= < Diameter Header: 123, REQ >
{ Origin-Host }
{ Origin-Realm }
* [ AVP ]

AA ::= < Diameter Header: 123 >
{ Result-Code }
{ Origin-Host }
{ Origin-Realm }
* [ AVP ]

BR ::= < Diameter Header: 124, REQ >
{ Origin-Host }
{ Origin-Realm }

BA ::= < Diameter Header: 124 >
{ Result-Code }
{ Origin-Host }
{ Origin-Realm }
* [ AVP ]
56 changes: 56 additions & 0 deletions lib/diameter/test/diameter_codec_SUITE_data/send.dia
@@ -0,0 +1,56 @@
;;
;; %CopyrightBegin%
;;
;; Copyright Ericsson AB 2010-2011. All Rights Reserved.
;;
;; The contents of this file are subject to the Erlang Public License,
;; Version 1.1, (the "License"); you may not use this file except in
;; compliance with the License. You should have received a copy of the
;; Erlang Public License along with this software. If not, it can be
;; retrieved online at http://www.erlang.org/.
;;
;; Software distributed under the License is distributed on an "AS IS"
;; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
;; the License for the specific language governing rights and limitations
;; under the License.
;;
;; %CopyrightEnd%
;;

@id 17
@name diameter_test_send
@prefix send

@inherits diameter_gen_base_rfc3588

Origin-Host
Origin-Realm
Result-Code

@inherits diameter_test_avps

@messages

AR ::= < Diameter Header: 123, REQ >
{ Origin-Host }
{ Origin-Realm }
[ XXX ]
[ YYY ]

AA ::= < Diameter Header: 123 >
{ Result-Code }
{ Origin-Host }
{ Origin-Realm }
* [ AVP ]

BR ::= < Diameter Header: 124, REQ >
{ Origin-Host }
{ Origin-Realm }
[ XXX ]
[ YYY ]

BA ::= < Diameter Header: 124 >
{ Result-Code }
{ Origin-Host }
{ Origin-Realm }
* [ AVP ]
6 changes: 6 additions & 0 deletions lib/diameter/test/modules.mk
Expand Up @@ -42,3 +42,9 @@ MODULES = \

HRL_FILES = \
diameter_ct.hrl

DATA = \
diameter_codec_SUITE_data/avps.dia \
diameter_codec_SUITE_data/send.dia \
diameter_codec_SUITE_data/recv.dia \
diameter_codec_SUITE_data/diameter_test_unknown.erl

0 comments on commit 859d947

Please sign in to comment.