forked from erlang/otp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codec testcase for decode of unknown AVPs
- Loading branch information
Anders Svensson
committed
Dec 16, 2011
1 parent
a2b669f
commit 859d947
Showing
7 changed files
with
249 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 - |
76 changes: 76 additions & 0 deletions
76
lib/diameter/test/diameter_codec_SUITE_data/diameter_test_unknown.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters