[MM-53799] Stop autocompleting while the user is typing https://
(#3202)
* [MM-53799] Stop autocompleting while the user is typing `https://` * PR feedback * Fix casing issue
This commit is contained in:
@@ -428,6 +428,38 @@ describe('app/serverViewState', () => {
|
|||||||
expect(result.validatedURL).toBe('https://server.com/');
|
expect(result.validatedURL).toBe('https://server.com/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not update the URL if the user is typing https://', async () => {
|
||||||
|
let result = await serverViewState.handleServerURLValidation({}, 'h');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'ht');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'htt');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'http');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'HTTP');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'https');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'HTTPS');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'https:');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'https:/');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'https://');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.Invalid);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'https://a');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.OK);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update the URL if the user is typing something other than http', async () => {
|
||||||
|
let result = await serverViewState.handleServerURLValidation({}, 'abchttp');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.OK);
|
||||||
|
result = await serverViewState.handleServerURLValidation({}, 'abchttps');
|
||||||
|
expect(result.status).toBe(URLValidationStatus.OK);
|
||||||
|
});
|
||||||
|
|
||||||
it('should attempt HTTP when HTTPS fails, and generate a warning', async () => {
|
it('should attempt HTTP when HTTPS fails, and generate a warning', async () => {
|
||||||
ServerInfo.mockImplementation(({url}) => ({
|
ServerInfo.mockImplementation(({url}) => ({
|
||||||
fetchConfigData: jest.fn().mockImplementation(() => {
|
fetchConfigData: jest.fn().mockImplementation(() => {
|
||||||
@@ -477,7 +509,7 @@ describe('app/serverViewState', () => {
|
|||||||
|
|
||||||
const result = await serverViewState.handleServerURLValidation({}, 'https://not-server.com');
|
const result = await serverViewState.handleServerURLValidation({}, 'https://not-server.com');
|
||||||
expect(result.status).toBe(URLValidationStatus.NotMattermost);
|
expect(result.status).toBe(URLValidationStatus.NotMattermost);
|
||||||
expect(result.validatedURL).toBe('https://not-server.com/');
|
expect(result.validatedURL).toBe('https://not-server.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the users URL when the Site URL is different', async () => {
|
it('should update the users URL when the Site URL is different', async () => {
|
||||||
|
@@ -238,11 +238,11 @@ export class ServerViewState {
|
|||||||
|
|
||||||
let httpUrl = url;
|
let httpUrl = url;
|
||||||
if (!isValidURL(url)) {
|
if (!isValidURL(url)) {
|
||||||
// If it already includes the protocol, tell them it's invalid
|
// If it already includes the protocol, force it to HTTPS
|
||||||
if (isValidURI(url)) {
|
if (isValidURI(url) && !url.toLowerCase().startsWith('http')) {
|
||||||
httpUrl = url.replace(/^((.+):\/\/)?/, 'https://');
|
httpUrl = url.replace(/^((.+):\/\/)?/, 'https://');
|
||||||
} else {
|
} else if (!'https://'.startsWith(url.toLowerCase()) && !'http://'.startsWith(url.toLowerCase())) {
|
||||||
// Otherwise add HTTPS for them
|
// Check if they're starting to type `http(s)`, otherwise add HTTPS for them
|
||||||
httpUrl = `https://${url}`;
|
httpUrl = `https://${url}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,8 +279,9 @@ export class ServerViewState {
|
|||||||
|
|
||||||
// If we can't get the remote info, warn the user that this might not be the right URL
|
// If we can't get the remote info, warn the user that this might not be the right URL
|
||||||
// If the original URL was invalid, don't replace that as they probably have a typo somewhere
|
// If the original URL was invalid, don't replace that as they probably have a typo somewhere
|
||||||
|
// Also strip the trailing slash if it's there so that the user can keep typing
|
||||||
if (!remoteInfo) {
|
if (!remoteInfo) {
|
||||||
return {status: URLValidationStatus.NotMattermost, validatedURL: parsedURL.toString()};
|
return {status: URLValidationStatus.NotMattermost, validatedURL: parsedURL.toString().replace(/\/$/, '')};
|
||||||
}
|
}
|
||||||
|
|
||||||
const remoteServerName = remoteInfo.siteName === 'Mattermost' ? remoteURL.host.split('.')[0] : remoteInfo.siteName;
|
const remoteServerName = remoteInfo.siteName === 'Mattermost' ? remoteURL.host.split('.')[0] : remoteInfo.siteName;
|
||||||
|
Reference in New Issue
Block a user