MT#11827 validate sip uri

Change-Id: I19281ec28eb6708e824963bef8a4e0523499add8
changes/21/1421/5
Gerhard Jungwirth 11 years ago
parent 63371e46af
commit a35314d0aa

@ -13,8 +13,8 @@ sub get_class_messages {
my $self = shift;
return {
%{ $self->next::method },
%$class_messages,
}
%{ $class_messages },
};
}
apply(
@ -22,7 +22,7 @@ apply(
{
transform => sub {
lc($_[0]);
}
},
},
{
transform => sub {
@ -40,19 +40,25 @@ apply(
if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") {
$user = NGCP::Panel::Utils::Subscriber::apply_rewrite(
c => $c, subscriber => $sub, number => $user, direction => 'callee_in'
c => $c, subscriber => $sub, number => $user, direction => 'callee_in',
);
}
$uri = 'sip:' . $user . '@' . $domain;
return $uri;
}
},
},
{
check => sub {
my ( $value, $field ) = @_;
my ($user, $domain) = split(/\@/, $value);
my $checked = $value if $user && $domain; # TODO: proper check
my $checked;
if ($user && $domain) {
if ( $user =~ m/^(sip:)?[a-zA-Z0-9\+\-\.]*$/ &&
$domain =~ m/^[^;\?:]*$/ ) {
$checked = $value;
}
}
$field->value($checked)
if $checked;
},
@ -60,8 +66,8 @@ apply(
my ( $value, $field ) = @_;
return $field->get_message('uri_format');
},
}
]
},
],
);
has '+deflate_method' => ( default => sub { \&uri_deflate } );
@ -80,7 +86,7 @@ sub uri_deflate {
my ($user, $domain) = split(/\@/, $v);
if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") {
$user = NGCP::Panel::Utils::Subscriber::apply_rewrite(
c => $c, subscriber => $sub, number => $user, direction => 'caller_out'
c => $c, subscriber => $sub, number => $user, direction => 'caller_out',
);
}
if($domain eq $sub->domain->domain) {

@ -1,5 +1,8 @@
package Test::WebDriver::Sipwise;
use Sipwise::Base;
use warnings;
use strict;
use Moo;
use MooseX::Method::Signatures;
extends 'Test::WebDriver';
method find(Str $scheme, Str $query) {
@ -30,12 +33,11 @@ method findtext(Str $text, Any $ignore) {
method save_screenshot() {
use MIME::Base64;
local *FH;
open(FH,'>','screenshot.png');
binmode FH;
open(my $FH,'>','screenshot.png');
binmode $FH;
my $png_base64 = $self->screenshot();
print FH decode_base64($png_base64);
close FH;
print $FH decode_base64($png_base64);
close $FH;
}
method fill_element(ArrayRef $options, Any $ignore) {
@ -51,5 +53,7 @@ method fill_element(ArrayRef $options, Any $ignore) {
sub browser_name_in {
my ($self, @names) = @_;
my $browser_name = $self->get_capabilities->{browserName};
return $browser_name ~~ @names;
return scalar grep {/^$browser_name$/} @names;
}
1;

@ -0,0 +1,88 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use NGCP::Panel::Form::SubscriberCFSimple;
my $configs = [
{
works => 1,
config => {
destination => {
destination => 'uri',
uri => { destination => 'sip:foo@bar.com' },
},
},
},
{
works => 1,
config => {
destination => {
destination => 'uri',
uri => { destination => 'foo@bar.com' },
},
},
},
{
works => 1,
config => {
destination => {
destination => 'uri',
uri => { destination => 'alice@10.0.0.1' },
},
},
},
{
works => 1,
config => {
destination => {
destination => 'uri',
uri => { destination => '12345@a' }, # we set a domain here, because on tests it cannot be automatically deduced from stash
},
},
},
{
works => 1,
config => {
destination => {
destination => 'uri',
uri => { destination => '+12345@a' },
},
},
},
{
works => 0,
config => {
destination => {
destination => 'uri',
uri => { destination => '12345[678]@a' },
},
},
},
{
works => 0,
config => {
destination => {
destination => 'uri',
uri => { destination => '+49(0)123456789@a' },
},
},
},
];
for my $conf (@{$configs}) {
my $form = NGCP::Panel::Form::SubscriberCFSimple->new;
$form->process(
posted => 1,
params => $conf->{config},
);
my $uri = $form->value->{destination}{uri}{destination};
if ($conf->{works}) {
ok($form->validated, "Should validate: $uri");
} else {
ok(!$form->validated, "Should not validate: $uri");
}
}
done_testing();
Loading…
Cancel
Save