Skip to content

Commit

Permalink
Fiexed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Jan 15, 2025
1 parent 98d5406 commit 3116e1f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static String generatePhoneVerification() {
}

public static String generateControlCode() {
return String.valueOf(random.nextInt(10000, 60000));
return String.valueOf(getChars(5, NUMBERS));
}

private static char[] getChars(int nbrBytes, char[] charArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import myconext.AbstractIntegrationTest;
import myconext.model.ControlCode;
import myconext.model.User;
import myconext.security.VerificationCodeGenerator;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.util.ReflectionTestUtils;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void testFindOneUserByEmail() {
public void testFindOneUserByControlCode() {
User user = userRepository.findOneUserByEmail("[email protected]");
ControlCode controlCode = new ControlCode();
controlCode.setCode("12345");
controlCode.setCode(VerificationCodeGenerator.generateControlCode());
user.setControlCode(controlCode);
userRepository.save(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class VerificationCodeGeneratorTest {

private final Pattern patternPhoneVerification = Pattern.compile("^[0-9]{6}$");

private final Pattern patternControlCode = Pattern.compile("^[0-9]{5}$");

@Test
public void generate() {
String code = VerificationCodeGenerator.generate();
Expand All @@ -32,4 +34,11 @@ public void generatePhoneVerification() {
String phoneVerification = VerificationCodeGenerator.generatePhoneVerification();
assertTrue(patternPhoneVerification.matcher(phoneVerification).matches());
}

@Test
public void generateControlCode() {
String controlCode = VerificationCodeGenerator.generateControlCode();
assertTrue(patternControlCode.matcher(controlCode).matches());
}

}
186 changes: 0 additions & 186 deletions servicedesk-gui/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ function validateResponse(showErrorDialog) {
};
}

// It is not allowed to put non ASCI characters in HTTP headers
function sanitizeHeader(s) {
if (typeof s === 'string' || s instanceof String) {
s = s.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
}
return isEmpty(s) ? "NON_ASCII_ONLY" : s;
}

function validFetch(path, options, headers = {}, showErrorDialog = true) {

const contentHeaders = {
Expand All @@ -50,10 +42,6 @@ function validFetch(path, options, headers = {}, showErrorDialog = true) {
"X-CSRF-TOKEN": useAppStore.getState().csrfToken,
...headers
};
const impersonator = useAppStore.getState().impersonator;
if (impersonator) {
contentHeaders["X-IMPERSONATE-ID"] = sanitizeHeader(useAppStore.getState().user.id);
}
const fetchOptions = Object.assign({}, {headers: contentHeaders}, options, {
credentials: "same-origin",
redirect: "manual",
Expand All @@ -73,15 +61,7 @@ function postPutJson(path, body, method, showErrorDialog = true) {
return fetchJson(path, {method: method, body: jsonBody}, {}, showErrorDialog);
}

function fetchDelete(path, showErrorDialog = true) {
return validFetch(path, {method: "delete"}, {}, showErrorDialog);
}

//Base
export function health() {
return fetchJson("/internal/health");
}

export function configuration() {
return fetchJson("/api/v1/users/config", {}, {}, false);
}
Expand All @@ -91,172 +71,6 @@ export function me() {
return fetchJson("/api/v1/users/me", {}, {}, false);
}

export function other(id) {
return fetchJson(`/api/v1/users/other/${id}`, {}, {}, false);
}

export function searchUsers(pagination = {}) {
const queryPart = paginationQueryParams(pagination, {})
return fetchJson(`/api/v1/users/search?${queryPart}`);
}

export function searchUsersByApplication(pagination = {}) {
const queryPart = paginationQueryParams(pagination, {})
return fetchJson(`/api/v1/users/search-by-application?${queryPart}`);
}

export function csrf() {
return fetchJson("/api/v1/csrf", {}, {}, false);
}

export function logout() {
return fetchJson("/api/v1/users/logout");
}

export function reportError(error) {
return postPutJson("/api/v1/users/error", error, "post");
}

//Invitations
export function invitationByHash(hash) {
return fetchJson(`/api/v1/invitations/public?hash=${hash}`, {}, {}, false);
}

export function newInvitation(invitationRequest) {
return postPutJson("/api/v1/invitations", invitationRequest, "POST");
}

export function acceptInvitation(hash, invitationId) {
const body = {hash: hash, invitationId: invitationId};
return postPutJson("/api/v1/invitations/accept", body, "POST", false);
}

export function invitationsByRoleId(roleId) {
return fetchJson(`/api/v1/invitations/roles/${roleId}`, {}, {}, false);
}

export function resendInvitation(invitationId) {
return postPutJson(`/api/v1/invitations/${invitationId}`, {}, "PUT");
}

export function deleteInvitation(invitationId) {
return fetchDelete(`/api/v1/invitations/${invitationId}`);
}

export function allInvitations() {
return fetchJson(`/api/v1/invitations/all`, {}, {}, false);
}

export function searchInvitations(roleId, pagination = {}) {
if (roleId) {
pagination.roleId = roleId;
}
const queryPart = paginationQueryParams(pagination, {})
return fetchJson(`/api/v1/invitations/search?${queryPart}`, {}, {}, false);
}

//Manage
export function allProviders() {
return fetchJson("/api/v1/manage/providers");
}

export function allApplications() {
return fetchJson("/api/v1/manage/applications")
}

export function organizationGUIDValidation(organizationGUID) {
return fetchJson(`/api/v1/manage/organization-guid-validation/${organizationGUID}`, {}, {}, false);
}

//Roles
export function rolesByApplication(force = true, pagination = {}) {
const queryPart = paginationQueryParams(pagination, {force: !!force})
return fetchJson(`/api/v1/roles?${queryPart}`);
}

export function rolesPerApplicationManageId(manageId) {
return fetchJson(`/api/v1/roles/application/${manageId}`);
}

export function roleByID(roleID, showErrorDialog = true) {
return fetchJson(`/api/v1/roles/${roleID}`, {}, {}, showErrorDialog);
}

export function createRole(role) {
return postPutJson("/api/v1/roles", role, "POST", false);
}

export function updateRole(role) {
return postPutJson("/api/v1/roles", role, "PUT", false);
}

export function deleteRole(role) {
return fetchDelete(`/api/v1/roles/${role.id}`, false);
}

//User roles
export function managersByRoleId(roleId) {
return fetchJson(`/api/v1/user_roles/managers/${roleId}`, {}, {}, false);
}

export function searchUserRolesByRoleId(roleId, isGuests, pagination = {}) {
const queryPart = paginationQueryParams(pagination, {})
return fetchJson(`/api/v1/user_roles/search/${roleId}/${isGuests}?${queryPart}`, {}, {}, false);
}

export function updateUserRoleEndData(userRoleId, endDate) {
return postPutJson("/api/v1/user_roles", {userRoleId, endDate}, "PUT");
}

export function consequencesRoleDeletion(roleId) {
return fetchJson(`/api/v1/user_roles//consequences/${roleId}`, {}, {}, true);
}

export function deleteUserRole(userRoleId, isGuest) {
return fetchDelete(`/api/v1/user_roles/${userRoleId}/${isGuest}`, false);
}

//API tokens
export function apiTokens() {
return fetchJson("/api/v1/tokens");
}

export function generateToken() {
return fetchJson("/api/v1/tokens/generate-token");
}

export function createToken(description) {
return postPutJson("/api/v1/tokens", {description: description}, "POST");
}

export function deleteToken(token) {
return fetchDelete(`/api/v1/tokens/${token.id}`);
}


//Validations
export function validate(type, value) {
return isEmpty(value) ? Promise.resolve({valid: true}) :
postPutJson("/api/v1/validations/validate", {type, value}, "POST");
}

//System
export function cronCleanup() {
return fetchJson("/api/v1/system/cron/cleanup")
}

export function cronExpiryNotifications() {
return fetchJson("/api/v1/system/cron/expiry-notifications")
}

export function expiryUserRoles() {
return fetchJson("/api/v1/system/expiry-user-roles")
}

export function performanceSeed() {
return postPutJson("/api/v1/system/performance-seed", {}, "PUT")
}

export function rolesUnknownInManage() {
return fetchJson("/api/v1/system/unknown-roles")
}
75 changes: 0 additions & 75 deletions servicedesk-gui/src/styles/circle.scss

This file was deleted.

0 comments on commit 3116e1f

Please sign in to comment.