#!/usr/bin/perl
package oAuthTest;
use base qw(Test::Unit::TestCase);
use RVL::oAuth;
sub new {
my $self = shift()->SUPER::new(@_);
# your state for fixture here
return $self;
}
sub set_up {
# provide fixture
my $self = shift;
$self->{conf} = {
'uid' => 'reseller',
'cp_perms' => 'root',
'url' => 'http://api.rvglobalstore.com/admincp',
'authorizekey' => '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOCB/7mdygup+zTOTsePFvJwBx
8GMvKJaGCKwtabM4Rmj40t6FGboAkYLWQh06hXe8x8WWJ0uDhzMeVYXzT1JIT3gy
efHCZVhuOY/yA2yd8eKD7T+ZEPMyMpypl/oCOn9l4EB0KhaUqNWHuNKMuv2Bnv/3
/6wzKF6HBs9qiPXsTwIDAQAB
-----END PUBLIC KEY-----'
};
}
sub tear_down {
# clean up after test
}
sub test_singleton {
my $self = shift;
my ($class) = RVL::oAuth::singleton({
'uid' => $self->{conf}->{'uid'},
'cp_perms' => $self->{conf}->{'cp_perms'},
'url' => $self->{conf}->{'url'},
});
$self->assert_equals($self->{conf}->{'uid'}, $class->{DSN}->{uid});
$self->assert_equals($self->{conf}->{'url'}, $class->{DSN}->{url});
my ($apiRes) = $class->request_apikey();
$self->assert(defined $apiRes->{'key'});
$self->assert(defined $apiRes->{'code'});
my ($pass) = $class->encryptPublic($self->{conf}->{'authorizekey'}, $apiRes->{'key'});
my ($publickey) = $class->decryptPublickey($apiRes->{'code'}, $pass);
$self->{'publickey'} = $publickey;
$self->assert(defined $self->{'publickey'});
my ($class2) = RVL::oAuth::singleton({
'uid' => $self->{conf}->{'uid'},
'publickey' => $self->{'publickey'},
'url' => $self->{conf}->{'url'},
});
my ($token) = $class2->getToken();
$class2->validateToken($token);
my ($data);
my $qurey = {'id' => 999};
$data = $class2->request('get', '/testconnect', $qurey);
$self->assert_equals($data->{'function'}, 'executeGet');
$self->assert_equals($data->{'ID'}, 999);
$data = $class2->request('post', '/testconnect', $qurey);
$self->assert_equals($data->{'function'}, 'executePost');
$self->assert_equals($data->{'ID'}, 999);
$data = $class2->request('put', '/testconnect', $qurey);
$self->assert_equals($data->{'function'}, 'executePut');
$self->assert_equals($data->{'ID'}, 999);
$data = $class2->request('delete', '/testconnect', $qurey);
$self->assert_equals($data->{'function'}, 'executeDelete');
$self->assert_equals($data->{'ID'}, 999);
}
1;
Copyright 2K16 - 2K18 Indonesian Hacker Rulez