Commit 65b85235 authored by chickahoona's avatar chickahoona

some more unittests

parent f2917174
......@@ -12,7 +12,8 @@ engines:
enabled: false
config:
languages:
- javascript
javascript:
mass_threshold: 60
eslint:
enabled: true
fixme:
......
......@@ -149,7 +149,7 @@
<form name="googleAuthenticatorForm" ng-if="view === 'google_authenticator_2fa'">
<!-- google_authenticator_2fa View -->
<div class="form-group">
<input type="text" class="form-control" id="gaToken" placeholder="Token"
<input type="text" class="form-control" id="gaToken" placeholder="Google Authenticator Token"
ng-model="googleAuthenticatorFormGAToken" required maxlength="6" minlength="6">
</div>
......@@ -164,7 +164,7 @@
<form name="yubikeyOTPForm" ng-if="view === 'yubikey_otp_2fa'">
<!-- yubikey_otp_2fa View -->
<div class="form-group">
<input type="text" class="form-control" id="yubikeyOTPToken" placeholder="Token"
<input type="text" class="form-control" id="yubikeyOTPToken" placeholder="YubiKey Token"
ng-model="yubikeyOTPFormToken" required ng-keyup="$event.keyCode == 13 && yubikey_otp_verify(yubikeyOTPFormToken)">
</div>
......
......@@ -145,6 +145,19 @@
var inputs = document.querySelectorAll("input:not(:disabled):not([readonly]):not([type=hidden])");
var modify_input_field = function(input) {
input.style.backgroundImage = 'url("'+background_image+'")';
input.style.backgroundPosition = 'center right';
input.style.backgroundRepeat = 'no-repeat';
input.addEventListener('mouseover', mouseOver);
input.addEventListener('mouseout', mouseOut);
input.addEventListener('mousemove', mouseMove);
input.addEventListener('click', click);
};
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type !== 'password') {
......@@ -166,30 +179,14 @@
continue;
// username field is inputs[r]
//inputs[r].style.backgroundColor = "blue";
inputs[r].style.backgroundImage = 'url("'+background_image+'")';
inputs[r].style.backgroundPosition = 'center right';
inputs[r].style.backgroundRepeat = 'no-repeat';
inputs[r].addEventListener('mouseover', mouseOver);
inputs[r].addEventListener('mouseout', mouseOut);
inputs[r].addEventListener('mousemove', mouseMove);
inputs[r].addEventListener('click', click);
modify_input_field(inputs[r]);
newForm.username = inputs[r];
break;
}
// Password field is inputs[i]
//inputs[i].style.backgroundColor = "yellow";
inputs[i].style.backgroundImage = 'url("'+background_image+'")';
inputs[i].style.backgroundPosition = 'center right';
inputs[i].style.backgroundRepeat = 'no-repeat';
inputs[i].addEventListener('mouseover', mouseOver);
inputs[i].addEventListener('mouseout', mouseOut);
inputs[i].addEventListener('mousemove', mouseMove);
inputs[i].addEventListener('click', click);
modify_input_field(inputs[i]);
newForm.password = inputs[i];
......@@ -220,22 +217,22 @@
*/
var on_fillpassword = function (data) {
var fill_field_helper = function(field, value) {
jQuery(field).focus();
field.value = value;
jQuery(field).blur();
jQuery(field).keydown();
jQuery(field).keyup();
jQuery(field).change();
};
for (var i = 0; i < myForms.length; i++) {
if(data.hasOwnProperty('username') && data.username !== '') {
jQuery(myForms[i].username).focus();
myForms[i].username.value = data.username;
jQuery(myForms[i].username).blur();
jQuery(myForms[i].username).keydown();
jQuery(myForms[i].username).keyup();
jQuery(myForms[i].username).change();
fill_field_helper(myForms[i].username, data.username);
}
if(data.hasOwnProperty('password') && data.password !== '') {
jQuery(myForms[i].password).focus();
myForms[i].password.value = data.password;
jQuery(myForms[i].password).blur();
jQuery(myForms[i].password).keydown();
jQuery(myForms[i].password).keyup();
jQuery(myForms[i].password).change();
fill_field_helper(myForms[i].password, data.password);
}
if (myForms.length === 1 //only 1 form
&& myForms[i].form !== null //we found the form
......
......@@ -114,7 +114,7 @@
<form name="googleAuthenticatorForm" ng-if="view === 'google_authenticator_2fa'">
<!-- google_authenticator_2fa View -->
<div class="form-group">
<input type="text" class="form-control" id="gaToken" placeholder="Token"
<input type="text" class="form-control" id="gaToken" placeholder="Google Authenticator Token"
ng-model="googleAuthenticatorFormGAToken" required maxlength="6" minlength="6">
</div>
......@@ -129,7 +129,7 @@
<form name="yubikeyOTPForm" ng-if="view === 'yubikey_otp_2fa'">
<!-- yubikey_otp_2fa View -->
<div class="form-group">
<input type="text" class="form-control" id="yubikeyOTPToken" placeholder="Token"
<input type="text" class="form-control" id="yubikeyOTPToken" placeholder="YubiKey Token"
ng-model="yubikeyOTPFormToken" required ng-keyup="$event.keyCode == 13 && yubikey_otp_verify(yubikeyOTPFormToken)">
</div>
......
(function () {
describe('Service: account test suite', function () {
beforeEach(module('psonocli'));
it('account exists', inject(function (account) {
expect(account).toBeDefined();
}));
var mockedStorage;
beforeEach(function () {
mockedStorage = {
find_one: function (db, search) {
switch (search['key']) {
case 'user_id':
return { 'value': 'fake_user_id' };
case 'user_username':
return { 'value': 'fake_user_username' };
case 'user_public_key':
return { 'value': 'fake_user_public_key' };
case 'user_email':
return { 'value': 'fake_user_email' };
case 'setting_email':
return { 'value': 'fake_setting_email' };
default:
console.log(search['key']);
return null;
}
}
};
module(function ($provide) {
$provide.value('storage', mockedStorage);
});
});
// Test Default account
it('default get_tabs', inject(function (account) {
var tabs = account.get_tabs();
expect(Object.prototype.toString.call( tabs ) === '[object Array]').toBeTruthy();
for(var i = 0; i < tabs.length; i++) {
expect(tabs[i].hasOwnProperty('key')).toBeTruthy();
expect(tabs[i].hasOwnProperty('title')).toBeTruthy();
}
}));
it('default get_account_detail:user_id', inject(function (account) {
expect(account.get_account_detail('user_id')).toBe('fake_user_id');
}));
it('default get_account_detail:user_username', inject(function (account) {
expect(account.get_account_detail('user_username')).toBe('fake_user_username');
}));
it('default get_account_detail:user_public_key', inject(function (account) {
expect(account.get_account_detail('user_public_key')).toBe('fake_user_public_key');
}));
it('default get_account_detail:user_email', inject(function (account) {
expect(account.get_account_detail('user_email')).toBe('fake_user_email');
}));
it('default get_account_detail:setting_email', inject(function (account) {
expect(account.get_account_detail('setting_email')).toBe('fake_user_email');
}));
it('default get_account ', inject(function (account) {
var acc = account.get_account();
expect(acc.hasOwnProperty('fields')).toBeTruthy();
}));
});
}).call();
......@@ -39,6 +39,50 @@
$httpBackend.flush();
}));
it('ga_verify', inject(function (apiClient) {
var token = 'a-token';
var ga_token = 'a-ga_token';
$httpBackend.when('POST', "https://www.psono.pw/server/authentication/ga-verify/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(data.token).toEqual(token);
expect(data.ga_token).toEqual(ga_token);
// return answer
return [200, {}];
});
expect(apiClient.ga_verify(token, ga_token)).toBeDefined();
$httpBackend.flush();
}));
it('yubikey_otp_verify', inject(function (apiClient) {
var token = 'a-token';
var yubikey_otp = 'a-yubikey_otp';
$httpBackend.when('POST', "https://www.psono.pw/server/authentication/yubikey-otp-verify/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(data.token).toEqual(token);
expect(data.yubikey_otp).toEqual(yubikey_otp);
// return answer
return [200, {}];
});
expect(apiClient.yubikey_otp_verify(token, yubikey_otp)).toBeDefined();
$httpBackend.flush();
}));
it('activate_token', inject(function (apiClient) {
var token = 'a-token';
......@@ -368,6 +412,27 @@
$httpBackend.flush();
}));
it('read_secret_undefined_secret_id', inject(function (apiClient) {
var token = 'a-token';
var session_secret_key = 'a-session_secret_key';
$httpBackend.when('GET', "https://www.psono.pw/server/secret/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(headers.Authorization).toEqual('Token ' + token);
// return answer
return [200, {}];
});
expect(apiClient.read_secret(token, session_secret_key)).toBeDefined();
$httpBackend.flush();
}));
it('create_secret', inject(function (apiClient) {
var token = 'a-token';
......@@ -838,6 +903,148 @@
$httpBackend.flush();
}));
it('create_ga', inject(function (apiClient) {
var token = 'a-token';
var session_secret_key = 'a-session_secret_key';
var title = 'a-title';
$httpBackend.when('PUT', "https://www.psono.pw/server/user/ga/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(headers.Authorization).toEqual('Token ' + token);
expect(data.title).toEqual(title);
// return answer
return [200, {}];
});
expect(apiClient.create_ga(token, session_secret_key, title)).toBeDefined();
$httpBackend.flush();
}));
it('read_ga', inject(function (apiClient) {
var token = 'a-token';
var session_secret_key = 'a-session_secret_key';
$httpBackend.when('GET', "https://www.psono.pw/server/user/ga/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(headers.Authorization).toEqual('Token ' + token);
// return answer
return [200, {}];
});
expect(apiClient.read_ga(token, session_secret_key)).toBeDefined();
$httpBackend.flush();
}));
it('delete_ga', inject(function (apiClient) {
var token = 'a-token';
var session_secret_key = 'a-session_secret_key';
var google_authenticator_id = 'a-google_authenticator_id';
$httpBackend.when('DELETE', "https://www.psono.pw/server/user/ga/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(headers.Authorization).toEqual('Token ' + token);
expect(data.google_authenticator_id).toEqual(google_authenticator_id);
// return answer
return [200, {}];
});
expect(apiClient.delete_ga(token, session_secret_key, google_authenticator_id)).toBeDefined();
$httpBackend.flush();
}));
it('create_yubikey_otp', inject(function (apiClient) {
var token = 'a-token';
var session_secret_key = 'a-session_secret_key';
var title = 'a-title';
var yubikey_otp = 'a-yubikey_otp';
$httpBackend.when('PUT', "https://www.psono.pw/server/user/yubikey-otp/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(headers.Authorization).toEqual('Token ' + token);
expect(data.title).toEqual(title);
expect(data.yubikey_otp).toEqual(yubikey_otp);
// return answer
return [200, {}];
});
expect(apiClient.create_yubikey_otp(token, session_secret_key, title, yubikey_otp)).toBeDefined();
$httpBackend.flush();
}));
it('read_yubikey_otp', inject(function (apiClient) {
var token = 'a-token';
var session_secret_key = 'a-session_secret_key';
$httpBackend.when('GET', "https://www.psono.pw/server/user/yubikey-otp/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(headers.Authorization).toEqual('Token ' + token);
// return answer
return [200, {}];
});
expect(apiClient.read_yubikey_otp(token, session_secret_key)).toBeDefined();
$httpBackend.flush();
}));
it('delete_yubikey_otp', inject(function (apiClient) {
var token = 'a-token';
var session_secret_key = 'a-session_secret_key';
var yubikey_otp_id = 'a-yubikey_otp_id';
$httpBackend.when('DELETE', "https://www.psono.pw/server/user/yubikey-otp/").respond(
function(method, url, data, headers, params) {
// Validate request parameters:
data = JSON.parse(data);
expect(headers.Authorization).toEqual('Token ' + token);
expect(data.yubikey_otp_id).toEqual(yubikey_otp_id);
// return answer
return [200, {}];
});
expect(apiClient.delete_yubikey_otp(token, session_secret_key, yubikey_otp_id)).toBeDefined();
$httpBackend.flush();
}));
it('create_share_link', inject(function (apiClient) {
var token = 'a-token';
......
......@@ -184,6 +184,34 @@
expect(helper.is_valid_username('abc') === true).toBeTruthy();
}));
it('remove_from_array', inject(function (helper) {
var array = [1, 2, 5, 7];
var search = 5;
var target = [1, 2, 7];
helper.remove_from_array(array, search);
expect(array).toEqual(target);
}));
it('remove_from_array_own_cmp_fct', inject(function (helper) {
var array = [1, 2, 5, 5, 7];
var search = 5;
var target = [5, 5];
var cmp_fct = function(a, b) {
return a !== b;
};
helper.remove_from_array(array, search, cmp_fct);
expect(array).toEqual(target);
}));
});
}).call();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment