You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcp-panel/t/unit-formhandler-field-uri.t

107 lines
2.4 KiB

#!/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' },
},
},
},
{
works => 1,
config => {
destination => {
destination => 'uri',
uri => { destination => 'alice@10.0.0.1:1234' },
},
},
},
{
works => 1,
config => {
destination => {
destination => 'uri',
uri => { destination => 'foo@bar.com:1234' },
},
},
},
];
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();