-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server] restrict allowed phone numbers
- Loading branch information
1 parent
689b7f8
commit 6b55247
Showing
7 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
components/gitpod-db/src/typeorm/migration/1663784254956-IndexPhoneNumber.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
import { columnExists } from "./helper/helper"; | ||
|
||
const D_B_USER = "d_b_user"; | ||
const COL_PHONE_NUMBER = "verificationPhoneNumber"; | ||
|
||
export class IndexPhoneNumber1663784254956 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
if (!(await columnExists(queryRunner, D_B_USER, COL_PHONE_NUMBER))) { | ||
await queryRunner.query( | ||
`ALTER TABLE ${D_B_USER} ADD INDEX (${COL_PHONE_NUMBER}), ALGORITHM=INPLACE, LOCK=NONE `, | ||
); | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) 2020 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import * as chai from "chai"; | ||
import { suite, test } from "mocha-typescript"; | ||
import { formatPhoneNumber } from "./phone-numbers"; | ||
const expect = chai.expect; | ||
|
||
@suite | ||
export class PhoneNumberSpec { | ||
@test public testFormatPhoneNumber() { | ||
const tests = [ | ||
["00123234254", "+123234254"], | ||
["+1 232 34 254", "+123234254"], | ||
["001 23234-254", "+123234254"], | ||
["0012swedfkwejfew32sdf3sdvsf sdv fsdv4254", "+123234254"], | ||
]; | ||
|
||
for (const test of tests) { | ||
expect(formatPhoneNumber(test[0]), "Values : " + JSON.stringify(test)).to.eq(test[1]); | ||
} | ||
} | ||
} | ||
module.exports = new PhoneNumberSpec(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
/** | ||
* a simply cleaning method, that removes all non numbers and repaces a leading '00' with a leading '+' sign. | ||
* | ||
* @param phoneNumber | ||
* @returns formatted phone number | ||
*/ | ||
export function formatPhoneNumber(phoneNumber: string): string { | ||
var cleanPhoneNumber = phoneNumber.trim(); | ||
if (cleanPhoneNumber.startsWith("+")) { | ||
cleanPhoneNumber = "00" + cleanPhoneNumber.substring(1); | ||
} | ||
cleanPhoneNumber = cleanPhoneNumber.replace(/\D/g, ""); | ||
if (cleanPhoneNumber.startsWith("00")) { | ||
cleanPhoneNumber = "+" + cleanPhoneNumber.substring(2); | ||
} | ||
return cleanPhoneNumber; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters