From 19c246a124d1962535b535682a106dc862cdcddd Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 10 Jul 2017 18:17:49 +0200 Subject: Test Result-Code 5009 in traffic suite Aka DIAMETER_AVP_OCCURS_TOO_MANY_TIMES. This reveals a fault. The RFC says this: A message was received that included an AVP that appeared more often than permitted in the message definition. The Failed-AVP AVP MUST be included and contain a copy of the first instance of the offending AVP that exceeded the maximum number of occurrences. The list of AVPs is reversed when diameter checks arities, so Failed-AVP contains the wrong AVP, causing the new testcase to fail. --- lib/diameter/test/diameter_traffic_SUITE.erl | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'lib/diameter/test') diff --git a/lib/diameter/test/diameter_traffic_SUITE.erl b/lib/diameter/test/diameter_traffic_SUITE.erl index fb69cd831e..eb3ee777ce 100644 --- a/lib/diameter/test/diameter_traffic_SUITE.erl +++ b/lib/diameter/test/diameter_traffic_SUITE.erl @@ -64,6 +64,7 @@ send_invalid_reject/1, send_unexpected_mandatory_decode/1, send_unexpected_mandatory/1, + send_too_many/1, send_long/1, send_maxlen/1, send_nopeer/1, @@ -234,6 +235,8 @@ ?'DIAMETER_BASE_RESULT-CODE_AVP_UNSUPPORTED'). -define(UNSUPPORTED_VERSION, ?'DIAMETER_BASE_RESULT-CODE_UNSUPPORTED_VERSION'). +-define(TOO_MANY, + ?'DIAMETER_BASE_RESULT-CODE_AVP_OCCURS_TOO_MANY_TIMES'). -define(REALM_NOT_SERVED, ?'DIAMETER_BASE_RESULT-CODE_REALM_NOT_SERVED'). -define(UNABLE_TO_DELIVER, @@ -411,6 +414,7 @@ tc() -> send_invalid_reject, send_unexpected_mandatory_decode, send_unexpected_mandatory, + send_too_many, send_long, send_maxlen, send_nopeer, @@ -549,7 +553,9 @@ rfc4005(Config) -> %% Ensure that result codes have the expected values. result_codes(_Config) -> - {2001, 3001, 3002, 3003, 3004, 3007, 3008, 3009, 5001, 5011, 5014} + {2001, + 3001, 3002, 3003, 3004, 3007, 3008, 3009, + 5001, 5009, 5011, 5014} = {?SUCCESS, ?COMMAND_UNSUPPORTED, ?UNABLE_TO_DELIVER, @@ -559,6 +565,7 @@ result_codes(_Config) -> ?INVALID_HDR_BITS, ?INVALID_AVP_BITS, ?AVP_UNSUPPORTED, + ?TOO_MANY, ?UNSUPPORTED_VERSION, ?INVALID_AVP_LENGTH}. @@ -691,6 +698,18 @@ send_unexpected_mandatory_decode(Config) -> data = <<12:32>>}]] = failed_avps(Avps, Config). +%% Try to two Auth-Application-Id in ASR expect 5009. +send_too_many(Config) -> + Req = ['ASR'], + + ['ASA' | #{'Session-Id' := _, + 'Result-Code' := ?TOO_MANY, + 'Failed-AVP' := Avps}] + = call(Config, Req), + [[#diameter_avp{name = 'Auth-Application-Id', + value = 42}]] + = failed_avps(Avps, Config). + %% Send an containing a faulty Grouped AVP (empty Proxy-Host in %% Proxy-Info) and expect that only the faulty AVP is sent in %% Failed-AVP. The encoded values of Proxy-Host and Proxy-State are @@ -1250,6 +1269,25 @@ prepare(Pkt, Caps, N, #group{client_dict = Dict0} = Group) <> = Bin, E#diameter_packet{bin = <>}; +prepare(Pkt, Caps, N, #group{client_dict = Dict0} = Group) + when N == send_too_many -> + Req = prepare(Pkt, Caps, Group), + + #diameter_packet{header = #diameter_header{length = L}, + bin = B} + = E + = diameter_codec:encode(Dict0, + Pkt#diameter_packet{msg = Req}), + M = L - 4 - 12, + <<1, L:24, + T:M/binary, + A:8/binary, D:4/binary>> + = B, + E#diameter_packet{bin = <<1, (L+12):24, + T/binary, + A/binary, D/binary, + A/binary, 42:32>>}; + prepare(Pkt, Caps, N, #group{client_dict = Dict0} = Group) when N == send_long_avp_length; N == send_short_avp_length; -- cgit v1.2.3 From a14ba6581063c4fca2edc36156e07c6582729e2e Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Thu, 13 Jul 2017 12:37:54 +0200 Subject: Use relaxed arity checks in traffic suite --- lib/diameter/test/diameter_traffic_SUITE.erl | 70 +++++++++++----------------- 1 file changed, 26 insertions(+), 44 deletions(-) (limited to 'lib/diameter/test') diff --git a/lib/diameter/test/diameter_traffic_SUITE.erl b/lib/diameter/test/diameter_traffic_SUITE.erl index eb3ee777ce..662d95e3ae 100644 --- a/lib/diameter/test/diameter_traffic_SUITE.erl +++ b/lib/diameter/test/diameter_traffic_SUITE.erl @@ -459,7 +459,8 @@ start_services(Config) -> = group(Config), ok = diameter:start_service(SN, [{decode_format, SD} | ?SERVICE(SN, Grp)]), - ok = diameter:start_service(CN, [{sequence, ?CLIENT_MASK} + ok = diameter:start_service(CN, [{sequence, ?CLIENT_MASK}, + {strict_arities, decode} | ?SERVICE(CN, Grp)]). add_transports(Config) -> @@ -700,14 +701,14 @@ send_unexpected_mandatory_decode(Config) -> %% Try to two Auth-Application-Id in ASR expect 5009. send_too_many(Config) -> - Req = ['ASR'], + Req = ['ASR', {'Auth-Application-Id', [?APP_ID, 44]}], ['ASA' | #{'Session-Id' := _, 'Result-Code' := ?TOO_MANY, 'Failed-AVP' := Avps}] = call(Config, Req), [[#diameter_avp{name = 'Auth-Application-Id', - value = 42}]] + value = 44}]] = failed_avps(Avps, Config). %% Send an containing a faulty Grouped AVP (empty Proxy-Host in @@ -883,7 +884,7 @@ send_detach(Config) -> %% Send a request which can't be encoded and expect {error, encode}. send_encode_error(Config) -> - {error, encode} = call(Config, ['STR']). %% No Termination-Cause + {error, encode} = call(Config, ['STR', {'Termination-Cause', huh}]). %% Send with filtering and expect success. send_destination_1(Config) -> @@ -904,14 +905,14 @@ send_destination_2(Config) -> %% unknown host or realm. send_destination_3(Config) -> Req = ['STR', {'Termination-Cause', ?LOGOUT}, - {'Destination-Realm', "unknown.org"}], + {'Destination-Realm', <<"unknown.org">>}], {error, no_connection} = call(Config, Req, [{filter, {all, [host, realm]}}]). send_destination_4(Config) -> #group{server_service = SN} = group(Config), Req = ['STR', {'Termination-Cause', ?LOGOUT}, - {'Destination-Host', [?HOST(SN, "unknown.org")]}], + {'Destination-Host', [?HOST(SN, ["unknown.org"])]}], {error, no_connection} = call(Config, Req, [{filter, {all, [host, realm]}}]). @@ -919,7 +920,7 @@ send_destination_4(Config) -> %% an unknown host or realm. send_destination_5(Config) -> Req = ['STR', {'Termination-Cause', ?LOGOUT}, - {'Destination-Realm', "unknown.org"}], + {'Destination-Realm', [<<"unknown.org">>]}], ?answer_message(?REALM_NOT_SERVED) = call(Config, Req). send_destination_6(Config) -> @@ -1269,25 +1270,6 @@ prepare(Pkt, Caps, N, #group{client_dict = Dict0} = Group) <> = Bin, E#diameter_packet{bin = <>}; -prepare(Pkt, Caps, N, #group{client_dict = Dict0} = Group) - when N == send_too_many -> - Req = prepare(Pkt, Caps, Group), - - #diameter_packet{header = #diameter_header{length = L}, - bin = B} - = E - = diameter_codec:encode(Dict0, - Pkt#diameter_packet{msg = Req}), - M = L - 4 - 12, - <<1, L:24, - T:M/binary, - A:8/binary, D:4/binary>> - = B, - E#diameter_packet{bin = <<1, (L+12):24, - T/binary, - A/binary, D/binary, - A/binary, 42:32>>}; - prepare(Pkt, Caps, N, #group{client_dict = Dict0} = Group) when N == send_long_avp_length; N == send_short_avp_length; @@ -1419,10 +1401,10 @@ set(N, #diameter_packet{msg = Req}, Caps, Group) origin_realm = {OR, DR}} = Caps, - set(Group, Req, [{'Session-Id', diameter:session_id(OH)}, - {'Origin-Host', OH}, - {'Origin-Realm', OR}, - {'Destination-Realm', DR}]); + set(Group, Req, [{'Session-Id', [diameter:session_id(OH)]}, + {'Origin-Host', [OH]}, + {'Origin-Realm', [OR]}, + {'Destination-Realm', [DR]}]); set(N, #diameter_packet{msg = Req}, Caps, Group) when N == {record, diameter_base_ASR}; @@ -1432,11 +1414,11 @@ set(N, #diameter_packet{msg = Req}, Caps, Group) #diameter_caps{origin_host = {OH, DH}, origin_realm = {OR, DR}} = Caps, - set(Group, Req, [{'Session-Id', diameter:session_id(OH)}, - {'Origin-Host', OH}, - {'Origin-Realm', OR}, - {'Destination-Host', DH}, - {'Destination-Realm', DR}, + set(Group, Req, [{'Session-Id', [diameter:session_id(OH)]}, + {'Origin-Host', [OH]}, + {'Origin-Realm', [OR]}, + {'Destination-Host', [DH]}, + {'Destination-Realm', [DR]}, {'Auth-Application-Id', ?APP_ID}]); set(N, #diameter_packet{msg = Req}, Caps, Group) @@ -1447,10 +1429,10 @@ set(N, #diameter_packet{msg = Req}, Caps, Group) #diameter_caps{origin_host = {OH, _}, origin_realm = {OR, DR}} = Caps, - set(Group, Req, [{'Session-Id', diameter:session_id(OH)}, - {'Origin-Host', OH}, - {'Origin-Realm', OR}, - {'Destination-Realm', DR}, + set(Group, Req, [{'Session-Id', [diameter:session_id(OH)]}, + {'Origin-Host', [OH]}, + {'Origin-Realm', [OR]}, + {'Destination-Realm', [DR]}, {'Auth-Application-Id', ?APP_ID}]); set(N, #diameter_packet{msg = Req}, Caps, Group) @@ -1461,11 +1443,11 @@ set(N, #diameter_packet{msg = Req}, Caps, Group) #diameter_caps{origin_host = {OH, DH}, origin_realm = {OR, DR}} = Caps, - set(Group, Req, [{'Session-Id', diameter:session_id(OH)}, - {'Origin-Host', OH}, - {'Origin-Realm', OR}, - {'Destination-Host', DH}, - {'Destination-Realm', DR}, + set(Group, Req, [{'Session-Id', [diameter:session_id(OH)]}, + {'Origin-Host', [OH]}, + {'Origin-Realm', [OR]}, + {'Destination-Host', [DH]}, + {'Destination-Realm', [DR]}, {'Auth-Application-Id', ?APP_ID}]). %% name/1 -- cgit v1.2.3