From 9670e6acf6036b67a21a6e73bc067f82a9b262e9 Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Sun, 22 Jan 2012 23:01:04 +0100 Subject: [PATCH] Tests for alias nodes --- api/t/alias.t | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 api/t/alias.t diff --git a/api/t/alias.t b/api/t/alias.t new file mode 100644 index 0000000..ac47b1c --- /dev/null +++ b/api/t/alias.t @@ -0,0 +1,126 @@ +#!/usr/bin/perl + +use strict; +use Test::More 'no_plan'; +use tests_common; +use Data::Dumper; + +# Configuration variables defined in tests_common +# Make sure those are updated/set correctly.. +# $api_base +# $api_key +# +# Further variables defined in tests_common: +# $invalid_key +# $test_username +# $test_password +# $invalid_username +my ($data, $temp, $test_number_start, $test_alias, $test_e164alias, $test_domain, $test_remote_domain); + +our $test_alias = "testalias-" . int(rand(255)); + +$test_e164alias .= int(rand(255)) + while ( length( $test_e164alias ) < 8 ); + +$test_e164alias = '+47' . substr( $test_e164alias, 0, 8 ); + +isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua'); +isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies'); + +login_apikey(); + +# First: fetch a supported domain from the API... +$data = exec_apinode("domain/list", undef); +ok($data, 'domain/list JSON decode'); +is( $data->{'response'}, 'ok', 'domain/list result'); +ok($data->{'list'}, 'domain/list array'); + +# NOW: Set the $test_domain to something useful (i.e. the first reported domain) +$test_domain = $data->{'list'}[0]; +$test_remote_domain = "external." . $test_domain; + +ok($test_domain, 'test_domain set.'); +ok($test_remote_domain, 'test_remote_domain set.'); +undef $data; + +$data = exec_apinode("user/available", { "user" => $test_username . "\@" . $test_domain }); +is( $data->{'response'}, 'ok', 'user/available is available'); +undef $data; + +$data = exec_apinode("user/add_local", { + "user" => $test_username . "\@" . $test_domain, + "displayname" => "Automatic testing", + "email" => "noreply\@" . $test_domain, +} ); +is( $data->{'response'}, 'ok', 'user/add_local created new account'); + +$data = exec_apinode("alias/list", undef); +is( $data->{'response'}, 'ok', 'alias/list result'); +ok($data->{'aliases'}, 'alias/list array'); +undef $data; + +$data = exec_apinode("alias/add", { + 'alias' => $test_alias . "\@" . $test_domain, + 'destination' => $test_username . "\@" . $test_domain, +}); +is( $data->{'response'}, 'ok', 'alias/add result'); +ok( $data->{'destination'}, 'alias/add destination'); +ok( $data->{'alias'}, 'alias/add alias'); +undef $data; + +$data = exec_apinode("alias/add", { + 'alias' => $test_alias . "\@" . $test_domain, + 'destination' => $test_username . "\@" . $test_domain, +}); +is( $data->{'response'}, 'failed', 'alias/add for existing alias result'); +undef $data; + + + +$data = exec_apinode("alias/add", { + 'alias' => $test_e164alias . "\@" . $test_domain, + 'destination' => $test_username . "\@" . $test_domain, +}); +is( $data->{'response'}, 'ok', 'alias/add e164 result'); +ok( $data->{'destination'}, 'alias/add destination'); +ok( $data->{'alias'}, 'alias/add alias'); +undef $data; + +$data = exec_apinode("alias/list", { 'destination' => $test_username . "\@" . $test_domain }); +is( $data->{'response'}, 'ok', 'alias/list w/destination result'); +ok($data->{'aliases'}, 'alias/list w/destination array'); +undef $data; + +$data = exec_apinode("alias/list", { 'destination' => $test_username . "\@" . $test_domain }); +is( $data->{'response'}, 'ok', 'alias/list w/e164 result'); +ok($data->{'aliases'}, 'alias/list w/e164 array'); +ok($data->{'aliases'}[0]->{'destination'}, 'alias/list w/e164 destination'); +undef $data; + +$data = exec_apinode("alias/remove", { + 'alias' => $test_alias . "\@" . $test_domain, +}); +is( $data->{'response'}, 'ok', 'alias/remove result'); +ok( $data->{'alias'}, 'alias/remove alias'); +undef $data; + +$data = exec_apinode("alias/remove", { + 'alias' => $test_e164alias . "\@" . $test_domain, +}); +is( $data->{'response'}, 'ok', 'alias/remove e164 result'); +ok( $data->{'alias'}, 'alias/remove alias'); +undef $data; + +$data = exec_apinode("user/remove", { "user" => $test_username . "\@" . $test_domain }); +is( $data->{'response'}, 'ok', 'user/remove deleted user'); +undef $data; + +$data = exec_apinode("alias/add", { + 'alias' => $test_username . "\@" . $test_domain, + 'destination' => $test_alias . "\@" . $test_domain, +}); +is( $data->{'response'}, 'failed', 'alias/add for existing user result'); +undef $data; + + +logout(); -- 2.39.2