mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-09 11:31:15 +00:00
Removing old authorization
This commit is contained in:
parent
ab6c43c167
commit
5cfda3500a
@ -23,20 +23,6 @@
|
||||
<mat-option *ngFor="let protocol of protocols" [value]="protocol.key"> {{ protocol.name }} </mat-option>
|
||||
</mat-select>
|
||||
</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>
|
||||
</mat-card>
|
||||
<div class="buttons-bar">
|
||||
|
@ -18,10 +18,6 @@ export class DirectLinkComponent implements OnInit {
|
||||
public serverPort;
|
||||
public projectId;
|
||||
|
||||
authorizations = [
|
||||
{ key: 'none', name: 'No authorization' },
|
||||
{ key: 'basic', name: 'Basic authorization' },
|
||||
];
|
||||
protocols = [
|
||||
{ key: 'http:', name: 'HTTP' },
|
||||
{ key: 'https:', name: 'HTTPS' },
|
||||
@ -34,10 +30,7 @@ export class DirectLinkComponent implements OnInit {
|
||||
serverForm = new FormGroup({
|
||||
name: new FormControl('', [Validators.required]),
|
||||
location: new FormControl(''),
|
||||
protocol: new FormControl('http:'),
|
||||
authorization: new FormControl('none'),
|
||||
login: new FormControl(''),
|
||||
password: new FormControl(''),
|
||||
protocol: new FormControl('http:')
|
||||
});
|
||||
|
||||
constructor(
|
||||
@ -80,11 +73,6 @@ export class DirectLinkComponent implements OnInit {
|
||||
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();
|
||||
serverToAdd.host = this.serverIp;
|
||||
serverToAdd.port = this.serverPort;
|
||||
@ -92,9 +80,6 @@ export class DirectLinkComponent implements OnInit {
|
||||
serverToAdd.name = this.serverForm.get('name').value;
|
||||
serverToAdd.location = this.serverForm.get('location').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.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-select>
|
||||
</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 mat-dialog-actions>
|
||||
<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',
|
||||
})
|
||||
export class AddServerDialogComponent implements OnInit {
|
||||
authorizations = [
|
||||
{ key: 'none', name: 'No authorization' },
|
||||
{ key: 'basic', name: 'Basic authorization' },
|
||||
];
|
||||
protocols = [
|
||||
{ key: 'http:', name: 'HTTP' },
|
||||
{ key: 'https:', name: 'HTTPS' },
|
||||
@ -28,10 +24,7 @@ export class AddServerDialogComponent implements OnInit {
|
||||
ubridge_path: new FormControl(''),
|
||||
host: new FormControl('', [Validators.required]),
|
||||
port: new FormControl('', [Validators.required, Validators.min(1)]),
|
||||
protocol: new FormControl('http:'),
|
||||
authorization: new FormControl('none'),
|
||||
login: new FormControl(''),
|
||||
password: new FormControl(''),
|
||||
protocol: new FormControl('http:')
|
||||
});
|
||||
|
||||
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();
|
||||
this.serverForm.get('location').setValue(defaultLocation);
|
||||
this.serverForm.get('host').setValue(this.getDefaultHost());
|
||||
this.serverForm.get('port').setValue(this.getDefaultPort());
|
||||
this.serverForm.get('authorization').setValue('none');
|
||||
}
|
||||
|
||||
onAddClick(): void {
|
||||
|
@ -52,7 +52,7 @@ export class ServersComponent implements OnInit, OnDestroy {
|
||||
servers.forEach((server) => {
|
||||
this.serverService.checkServerVersion(server).subscribe(
|
||||
(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 (!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 ServerStatus = 'stopped' | 'starting' | 'running';
|
||||
export type ServerProtocol = 'http:' | 'https:';
|
||||
@ -11,9 +10,6 @@ export class Server {
|
||||
port: number;
|
||||
path: string;
|
||||
ubridge_path: string;
|
||||
authorization: ServerAuthorization;
|
||||
login: string;
|
||||
password: string;
|
||||
status: ServerStatus;
|
||||
protocol: ServerProtocol;
|
||||
}
|
||||
|
@ -183,39 +183,6 @@ describe('HttpServer', () => {
|
||||
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', () => {
|
||||
server.host = null;
|
||||
server.port = null;
|
||||
|
@ -187,10 +187,10 @@ export class HttpServer {
|
||||
options.headers = {};
|
||||
}
|
||||
|
||||
if (server.authorization === 'basic') {
|
||||
const credentials = btoa(`${server.login}:${server.password}`);
|
||||
options.headers['Authorization'] = `Basic ${credentials}`;
|
||||
}
|
||||
// if (server.authorization === 'basic') {
|
||||
// const credentials = btoa(`${server.login}:${server.password}`);
|
||||
// options.headers['Authorization'] = `Basic ${credentials}`;
|
||||
// }
|
||||
|
||||
return {
|
||||
url: url,
|
||||
|
@ -30,7 +30,6 @@ describe('TemplateService', () => {
|
||||
const server = new Server();
|
||||
server.host = '127.0.0.1';
|
||||
server.port = 3080;
|
||||
server.authorization = 'none';
|
||||
|
||||
service.list(server).subscribe(() => {});
|
||||
|
||||
|
@ -4,7 +4,6 @@ export function getTestServer(): Server {
|
||||
const server = new Server();
|
||||
server.host = '127.0.0.1';
|
||||
server.port = 3080;
|
||||
server.authorization = 'none';
|
||||
server.protocol = 'http:';
|
||||
return server;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user