mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-19 23:33:43 +00:00
Removing old authorization
This commit is contained in:
@ -23,20 +23,6 @@
|
|||||||
<mat-option *ngFor="let protocol of protocols" [value]="protocol.key"> {{ protocol.name }} </mat-option>
|
<mat-option *ngFor="let protocol of protocols" [value]="protocol.key"> {{ protocol.name }} </mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field *ngIf="serverForm.get('location').value === 'remote'">
|
|
||||||
<mat-select placeholder="Authorization" formControlName="authorization">
|
|
||||||
<mat-option *ngFor="let auth of authorizations" [value]="auth.key"> {{ auth.name }} </mat-option>
|
|
||||||
</mat-select>
|
|
||||||
</mat-form-field>
|
|
||||||
|
|
||||||
<mat-form-field *ngIf="serverForm.get('authorization').value === 'basic'">
|
|
||||||
<input matInput tabindex="1" formControlName="login" placeholder="Login" />
|
|
||||||
</mat-form-field>
|
|
||||||
|
|
||||||
<mat-form-field *ngIf="serverForm.get('authorization').value === 'basic'">
|
|
||||||
<input matInput type="password" tabindex="1" formControlName="password" placeholder="Password" />
|
|
||||||
</mat-form-field>
|
|
||||||
</form>
|
</form>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<div class="buttons-bar">
|
<div class="buttons-bar">
|
||||||
|
@ -18,10 +18,6 @@ export class DirectLinkComponent implements OnInit {
|
|||||||
public serverPort;
|
public serverPort;
|
||||||
public projectId;
|
public projectId;
|
||||||
|
|
||||||
authorizations = [
|
|
||||||
{ key: 'none', name: 'No authorization' },
|
|
||||||
{ key: 'basic', name: 'Basic authorization' },
|
|
||||||
];
|
|
||||||
protocols = [
|
protocols = [
|
||||||
{ key: 'http:', name: 'HTTP' },
|
{ key: 'http:', name: 'HTTP' },
|
||||||
{ key: 'https:', name: 'HTTPS' },
|
{ key: 'https:', name: 'HTTPS' },
|
||||||
@ -34,10 +30,7 @@ export class DirectLinkComponent implements OnInit {
|
|||||||
serverForm = new FormGroup({
|
serverForm = new FormGroup({
|
||||||
name: new FormControl('', [Validators.required]),
|
name: new FormControl('', [Validators.required]),
|
||||||
location: new FormControl(''),
|
location: new FormControl(''),
|
||||||
protocol: new FormControl('http:'),
|
protocol: new FormControl('http:')
|
||||||
authorization: new FormControl('none'),
|
|
||||||
login: new FormControl(''),
|
|
||||||
password: new FormControl(''),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -80,11 +73,6 @@ export class DirectLinkComponent implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.serverForm.get('authorization').value === 'basic' && !this.serverForm.get('login').value && !this.serverForm.get('password').value) {
|
|
||||||
this.toasterService.error('Please use correct values');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let serverToAdd: Server = new Server();
|
let serverToAdd: Server = new Server();
|
||||||
serverToAdd.host = this.serverIp;
|
serverToAdd.host = this.serverIp;
|
||||||
serverToAdd.port = this.serverPort;
|
serverToAdd.port = this.serverPort;
|
||||||
@ -92,9 +80,6 @@ export class DirectLinkComponent implements OnInit {
|
|||||||
serverToAdd.name = this.serverForm.get('name').value;
|
serverToAdd.name = this.serverForm.get('name').value;
|
||||||
serverToAdd.location = this.serverForm.get('location').value;
|
serverToAdd.location = this.serverForm.get('location').value;
|
||||||
serverToAdd.protocol = this.serverForm.get('protocol').value;
|
serverToAdd.protocol = this.serverForm.get('protocol').value;
|
||||||
serverToAdd.authorization = this.serverForm.get('authorization').value;
|
|
||||||
serverToAdd.login = this.serverForm.get('login').value;
|
|
||||||
serverToAdd.password = this.serverForm.get('password').value;
|
|
||||||
|
|
||||||
this.serverService.create(serverToAdd).then((addedServer: Server) => {
|
this.serverService.create(serverToAdd).then((addedServer: Server) => {
|
||||||
this.router.navigate(['/server', addedServer.id, 'project', this.projectId]);
|
this.router.navigate(['/server', addedServer.id, 'project', this.projectId]);
|
||||||
|
@ -33,20 +33,6 @@
|
|||||||
<mat-option *ngFor="let protocol of protocols" [value]="protocol.key"> {{ protocol.name }} </mat-option>
|
<mat-option *ngFor="let protocol of protocols" [value]="protocol.key"> {{ protocol.name }} </mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field *ngIf="serverForm.get('location').value === 'remote'">
|
|
||||||
<mat-select placeholder="Authorization" formControlName="authorization">
|
|
||||||
<mat-option *ngFor="let auth of authorizations" [value]="auth.key"> {{ auth.name }} </mat-option>
|
|
||||||
</mat-select>
|
|
||||||
</mat-form-field>
|
|
||||||
|
|
||||||
<mat-form-field *ngIf="serverForm.get('authorization').value === 'basic'">
|
|
||||||
<input matInput tabindex="1" formControlName="login" placeholder="Login" />
|
|
||||||
</mat-form-field>
|
|
||||||
|
|
||||||
<mat-form-field *ngIf="serverForm.get('authorization').value === 'basic'">
|
|
||||||
<input matInput type="password" tabindex="1" formControlName="password" placeholder="Password" />
|
|
||||||
</mat-form-field>
|
|
||||||
</div>
|
</div>
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions>
|
||||||
<button mat-button (click)="onNoClick()" tabindex="-1" color="accent">No Thanks</button>
|
<button mat-button (click)="onNoClick()" tabindex="-1" color="accent">No Thanks</button>
|
||||||
|
@ -11,10 +11,6 @@ import { ToasterService } from '../../../services/toaster.service';
|
|||||||
templateUrl: 'add-server-dialog.component.html',
|
templateUrl: 'add-server-dialog.component.html',
|
||||||
})
|
})
|
||||||
export class AddServerDialogComponent implements OnInit {
|
export class AddServerDialogComponent implements OnInit {
|
||||||
authorizations = [
|
|
||||||
{ key: 'none', name: 'No authorization' },
|
|
||||||
{ key: 'basic', name: 'Basic authorization' },
|
|
||||||
];
|
|
||||||
protocols = [
|
protocols = [
|
||||||
{ key: 'http:', name: 'HTTP' },
|
{ key: 'http:', name: 'HTTP' },
|
||||||
{ key: 'https:', name: 'HTTPS' },
|
{ key: 'https:', name: 'HTTPS' },
|
||||||
@ -28,10 +24,7 @@ export class AddServerDialogComponent implements OnInit {
|
|||||||
ubridge_path: new FormControl(''),
|
ubridge_path: new FormControl(''),
|
||||||
host: new FormControl('', [Validators.required]),
|
host: new FormControl('', [Validators.required]),
|
||||||
port: new FormControl('', [Validators.required, Validators.min(1)]),
|
port: new FormControl('', [Validators.required, Validators.min(1)]),
|
||||||
protocol: new FormControl('http:'),
|
protocol: new FormControl('http:')
|
||||||
authorization: new FormControl('none'),
|
|
||||||
login: new FormControl(''),
|
|
||||||
password: new FormControl(''),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -120,30 +113,10 @@ export class AddServerDialogComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.serverForm.get('authorization').valueChanges.subscribe((authorization: string) => {
|
|
||||||
const loginControl = this.serverForm.get('login');
|
|
||||||
const passwordControl = this.serverForm.get('password');
|
|
||||||
|
|
||||||
if (authorization === 'none') {
|
|
||||||
loginControl.clearValidators();
|
|
||||||
passwordControl.clearValidators();
|
|
||||||
} else {
|
|
||||||
loginControl.setValidators([Validators.required]);
|
|
||||||
passwordControl.setValidators([Validators.required]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[loginControl, passwordControl].forEach((control) => {
|
|
||||||
control.updateValueAndValidity({
|
|
||||||
onlySelf: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const defaultLocation = await this.getDefaultLocation();
|
const defaultLocation = await this.getDefaultLocation();
|
||||||
this.serverForm.get('location').setValue(defaultLocation);
|
this.serverForm.get('location').setValue(defaultLocation);
|
||||||
this.serverForm.get('host').setValue(this.getDefaultHost());
|
this.serverForm.get('host').setValue(this.getDefaultHost());
|
||||||
this.serverForm.get('port').setValue(this.getDefaultPort());
|
this.serverForm.get('port').setValue(this.getDefaultPort());
|
||||||
this.serverForm.get('authorization').setValue('none');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddClick(): void {
|
onAddClick(): void {
|
||||||
|
@ -52,7 +52,7 @@ export class ServersComponent implements OnInit, OnDestroy {
|
|||||||
servers.forEach((server) => {
|
servers.forEach((server) => {
|
||||||
this.serverService.checkServerVersion(server).subscribe(
|
this.serverService.checkServerVersion(server).subscribe(
|
||||||
(serverInfo) => {
|
(serverInfo) => {
|
||||||
if (serverInfo.version.split('.')[1] >= 2 && serverInfo.version.split('.')[0] >= 2) {
|
if (serverInfo.version.split('.')[0] >= 3) {
|
||||||
if (!server.protocol) server.protocol = location.protocol as ServerProtocol;
|
if (!server.protocol) server.protocol = location.protocol as ServerProtocol;
|
||||||
if (!this.serverDatabase.find(server.name)) this.serverDatabase.addServer(server);
|
if (!this.serverDatabase.find(server.name)) this.serverDatabase.addServer(server);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
export type ServerAuthorization = 'basic' | 'none';
|
|
||||||
export type ServerLocation = 'local' | 'remote' | 'bundled';
|
export type ServerLocation = 'local' | 'remote' | 'bundled';
|
||||||
export type ServerStatus = 'stopped' | 'starting' | 'running';
|
export type ServerStatus = 'stopped' | 'starting' | 'running';
|
||||||
export type ServerProtocol = 'http:' | 'https:';
|
export type ServerProtocol = 'http:' | 'https:';
|
||||||
@ -11,9 +10,6 @@ export class Server {
|
|||||||
port: number;
|
port: number;
|
||||||
path: string;
|
path: string;
|
||||||
ubridge_path: string;
|
ubridge_path: string;
|
||||||
authorization: ServerAuthorization;
|
|
||||||
login: string;
|
|
||||||
password: string;
|
|
||||||
status: ServerStatus;
|
status: ServerStatus;
|
||||||
protocol: ServerProtocol;
|
protocol: ServerProtocol;
|
||||||
}
|
}
|
||||||
|
@ -183,39 +183,6 @@ describe('HttpServer', () => {
|
|||||||
expect(req.request.responseType).toEqual('json');
|
expect(req.request.responseType).toEqual('json');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add headers for `basic` authorization', () => {
|
|
||||||
server.authorization = 'basic';
|
|
||||||
server.login = 'login';
|
|
||||||
server.password = 'password';
|
|
||||||
|
|
||||||
service.get(server, '/test').subscribe();
|
|
||||||
|
|
||||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v3/test');
|
|
||||||
expect(req.request.method).toEqual('GET');
|
|
||||||
expect(req.request.responseType).toEqual('json');
|
|
||||||
expect(req.request.headers.get('Authorization')).toEqual('Basic bG9naW46cGFzc3dvcmQ=');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add headers for `basic` authorization and preserve headers', () => {
|
|
||||||
server.authorization = 'basic';
|
|
||||||
server.login = 'login';
|
|
||||||
server.password = 'password';
|
|
||||||
|
|
||||||
service
|
|
||||||
.get(server, '/test', {
|
|
||||||
headers: {
|
|
||||||
CustomHeader: 'value',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v3/test');
|
|
||||||
expect(req.request.method).toEqual('GET');
|
|
||||||
expect(req.request.responseType).toEqual('json');
|
|
||||||
expect(req.request.headers.get('Authorization')).toEqual('Basic bG9naW46cGFzc3dvcmQ=');
|
|
||||||
expect(req.request.headers.get('CustomHeader')).toEqual('value');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should make local call when ip and port is not defined', () => {
|
it('should make local call when ip and port is not defined', () => {
|
||||||
server.host = null;
|
server.host = null;
|
||||||
server.port = null;
|
server.port = null;
|
||||||
|
@ -187,10 +187,10 @@ export class HttpServer {
|
|||||||
options.headers = {};
|
options.headers = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.authorization === 'basic') {
|
// if (server.authorization === 'basic') {
|
||||||
const credentials = btoa(`${server.login}:${server.password}`);
|
// const credentials = btoa(`${server.login}:${server.password}`);
|
||||||
options.headers['Authorization'] = `Basic ${credentials}`;
|
// options.headers['Authorization'] = `Basic ${credentials}`;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -30,7 +30,6 @@ describe('TemplateService', () => {
|
|||||||
const server = new Server();
|
const server = new Server();
|
||||||
server.host = '127.0.0.1';
|
server.host = '127.0.0.1';
|
||||||
server.port = 3080;
|
server.port = 3080;
|
||||||
server.authorization = 'none';
|
|
||||||
|
|
||||||
service.list(server).subscribe(() => {});
|
service.list(server).subscribe(() => {});
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ export function getTestServer(): Server {
|
|||||||
const server = new Server();
|
const server = new Server();
|
||||||
server.host = '127.0.0.1';
|
server.host = '127.0.0.1';
|
||||||
server.port = 3080;
|
server.port = 3080;
|
||||||
server.authorization = 'none';
|
|
||||||
server.protocol = 'http:';
|
server.protocol = 'http:';
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user