Skip to content

Commit

Permalink
Feature/incorrect redirect url handling (#138)
Browse files Browse the repository at this point in the history
* Return Observable instead of just null

* Add karma test

* Handle all errors

* Cypress test for invalid IDs and invalid URLs

* Dynamic ID for test
  • Loading branch information
garyluu authored Nov 10, 2017
1 parent 57cdae1 commit 30e1360
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 27 deletions.
46 changes: 28 additions & 18 deletions cypress/integration/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ describe('Dropdown test', function() {
});

it('Should show all accounts as linked (except GitLab and Bitbucket)', function() {
cy
.get('h4').contains('GitHub').contains('Unlink Account')
cy
.get('h4').contains('Quay.io').contains('Unlink Account')
cy
.get('h4').contains('Bitbucket').contains('Link Account')
cy
.get('h4').contains('GitLab').contains('Link Account')
everythingOk();
});
});

var everythingOk = function() {
cy.get('#unlink-GitHub').should('be.visible')
cy.get('#unlink-Quay').should('be.visible')
cy.get('#link-Bitbucket').should('be.visible')
cy.get('#link-GitLab').should('be.visible')
}
describe('Go to setup page', function() {
beforeEach(function() {
// Select dropdown setup
Expand All @@ -57,16 +55,28 @@ describe('Dropdown test', function() {
});

it('Should show all accounts as linked (except GitLab and Bitbucket)', function() {
cy
.get('h4').contains('GitHub').contains('Unlink Account')
cy
.get('h4').contains('Quay.io').contains('Unlink Account')
cy
.get('h4').contains('Bitbucket').contains('Link Account')
cy
.get('h4').contains('GitLab').contains('Link Account')
everythingOk();
cy.visit('http://localhost:4200/auth/gitlab.com?code=somefakeid', {'failOnStatusCode': false}).then((resp) => {
expect(resp.status).to.eq('')
})
everythingOk();
cy.visit('http://localhost:4200/auth/bitbucket.org?code=somefakeid', {'failOnStatusCode': false}).then((resp) => {
expect(resp.status).to.eq('')
})
everythingOk();
cy.visit('http://localhost:4200/auth/potato.com?code=somefakeid', {'failOnStatusCode': false}).then((resp) => {
expect(resp.status).to.eq('')
})
everythingOk();
cy.visit('http://localhost:4200/auth/github.com?code=somefakeid', {'failOnStatusCode': false}).then((resp) => {
expect(resp.status).to.eq('')
})
everythingOk();
cy.visit('http://localhost:4200/auth/quay.io?code=somefakeid', {'failOnStatusCode': false}).then((resp) => {
expect(resp.status).to.eq('')
})
everythingOk();
});

// TODO: this part of the wizard has been reworked
// it('Go through steps', function() {
// // Should start on step 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div *ngFor="let row of accountsInfo">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">{{ row.name }}
<h4 class="panel-title">{{ row.name }} Account
<span *ngIf="row.isLinked">
<span class="label label-success">
<span class="glyphicon glyphicon-link"></span>
Expand All @@ -24,12 +24,12 @@ <h4 class="panel-title">{{ row.name }}
</span>
</span>
</span>
<button class="pull-right btn btn-default btn-sm" (click)="unlink(row.source)">
<button [attr.id]="'unlink-' + row.name" class="pull-right btn btn-default btn-sm" (click)="unlink(row.source)">
<span class="text-danger glyphicon glyphicon-link"></span>
<span class="text-danger">Unlink Account</span>
</button>
</span>
<button *ngIf="!row.isLinked" class="pull-right btn btn-primary btn-sm" (click)="link(row.source)">
<button [attr.id]="'link-' + row.name" *ngIf="!row.isLinked" class="pull-right btn btn-primary btn-sm" (click)="link(row.source)">
<span class="glyphicon glyphicon-link"></span>
<span>Link Account</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ export class AccountsExternalComponent implements OnInit, OnDestroy {

accountsInfo: Array<any> = [
{
name: 'GitHub Account',
name: 'GitHub',
source: TokenSource.GITHUB,
bold: 'Required',
message: 'GitHub credentials are used for login purposes as well as for pulling source code from GitHub.',
show: false
},
{
name: 'Quay.io Account',
name: 'Quay',
source: TokenSource.QUAY,
bold: 'Optional',
message: 'Quay.io credentials are used for pulling information about Docker images and automated builds.',
show: false
},
{
name: 'Bitbucket Account',
name: 'Bitbucket',
source: TokenSource.BITBUCKET,
bold: 'Optional',
message: 'Bitbucket credentials are used for pulling source code from Bitbucket.',
show: false
},
{
name: 'GitLab Account',
name: 'GitLab',
source: TokenSource.GITLAB,
bold: 'Optional',
message: 'GitLab credentials are used for pulling source code from GitLab.',
Expand Down
30 changes: 30 additions & 0 deletions src/app/loginComponents/auth/auth.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { RouterTestingModule } from '@angular/router/testing';
import { TokensStubService, TokenStubService } from './../../test/service-stubs';
import { TokenService } from '../token.service';
import { AuthComponent } from './auth.component';
import { TestBed, ComponentFixture, async } from '@angular/core/testing';


describe('AuthComponent', () => {
let component: AuthComponent;
let fixture: ComponentFixture<AuthComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AuthComponent],
imports: [ RouterTestingModule ],
providers: [{provide: TokenService, useClass: TokenStubService}]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AuthComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
});
8 changes: 6 additions & 2 deletions src/app/loginComponents/auth/auth.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class AuthComponent implements OnInit, OnDestroy {
return addGitLabToken;
default: {
console.log('Unknown provider: ' + provider);
return null;
return Observable.of(null);
}
}
});
Expand All @@ -68,7 +68,11 @@ export class AuthComponent implements OnInit, OnDestroy {
const prevPage = localStorage.getItem('page');

this.tokenSubscription = this.addToken().subscribe(token => {
this.tokenService.updateTokens();
if (token) {
this.tokenService.updateTokens();
}
this.router.navigate([`${ prevPage }`]);
}, error => {
this.router.navigate([`${ prevPage }`]);
});
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/test/service-stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ export class UserStubService {
user$ = Observable.of({});
}

export class TokenStubService {
updateTokens(): void {
}
}

export class TokensStubService {
public addQuayToken(accessToken?: string, extraHttpRequestParams?: any): Observable<Token> {
return Observable.of(quayToken);
Expand Down

0 comments on commit 30e1360

Please sign in to comment.