Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/errors.spec.js
/** | /** | ||||
* Copyright (C) 2019 The Software Heritage developers | * Copyright (C) 2019 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
import {httpGetJson} from '../utils'; | import {httpGetJson} from '../utils'; | ||||
const unarchivedRepo = { | let origin; | ||||
url: 'https://github.com/SoftwareHeritage/swh-web', | |||||
revisionSha1git: '7bf1b2f489f16253527807baead7957ca9e8adde', | |||||
snapshotSha1git: 'd9829223095de4bb529790de8ba4e4813e38672d', | |||||
rootDirSha1git: '7d887d96c0047a77e2e8c4ee9bb1528463677663', | |||||
readmeSha1git: 'b203ec39300e5b7e97b6e20986183cbd0b797859' | |||||
}; | |||||
const archivedRepo = { | |||||
url: 'https://github.com/memononen/libtess2', | |||||
invalidSubDir: 'Source1' | |||||
}; | |||||
const invalidChecksum = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; | const invalidChecksum = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; | ||||
const invalidPageUrl = '/invalidPath'; | const invalidPageUrl = '/invalidPath'; | ||||
function urlShouldShowError(url, error) { | function urlShouldShowError(url, error) { | ||||
cy.visit(url, { | cy.visit(url, { | ||||
failOnStatusCode: false | failOnStatusCode: false | ||||
}); | }); | ||||
cy.get('.swh-http-error') | cy.get('.swh-http-error') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.get('.swh-http-error-code') | cy.get('.swh-http-error-code') | ||||
.should('contain', error.code); | .should('contain', error.code); | ||||
cy.get('.swh-http-error-desc') | cy.get('.swh-http-error-desc') | ||||
.should('contain', error.msg); | .should('contain', error.msg); | ||||
} | } | ||||
describe('Test Errors', function() { | describe('Test Errors', function() { | ||||
before(function() { | |||||
origin = this.origin[0]; | |||||
}); | |||||
it('should show navigation buttons on error page', function() { | it('should show navigation buttons on error page', function() { | ||||
cy.visit(invalidPageUrl, { | cy.visit(invalidPageUrl, { | ||||
failOnStatusCode: false | failOnStatusCode: false | ||||
}); | }); | ||||
cy.get('a[onclick="window.history.back();"]') | cy.get('a[onclick="window.history.back();"]') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.get('a[href="/"') | cy.get('a[href="/"') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
}); | }); | ||||
context('For unarchived repositories', function() { | context('For unarchived repositories', function() { | ||||
it('should display NotFoundExc for unarchived repo', function() { | it('should display NotFoundExc for unarchived repo', function() { | ||||
const url = this.Urls.browse_origin_directory(unarchivedRepo.url); | const url = this.Urls.browse_origin_directory(this.unarchivedRepo.url); | ||||
urlShouldShowError(url, { | urlShouldShowError(url, { | ||||
code: '404', | code: '404', | ||||
msg: 'NotFoundExc: Origin with url ' + unarchivedRepo.url + ' not found!' | msg: 'NotFoundExc: Origin with url ' + this.unarchivedRepo.url + ' not found!' | ||||
}); | }); | ||||
}); | }); | ||||
it('should display NotFoundExc for unarchived content', function() { | it('should display NotFoundExc for unarchived content', function() { | ||||
const url = this.Urls.browse_content(`sha1_git:${unarchivedRepo.readmeSha1git}`); | const url = this.Urls.browse_content(`sha1_git:${this.unarchivedRepo.content[0].sha1git}`); | ||||
urlShouldShowError(url, { | urlShouldShowError(url, { | ||||
code: '404', | code: '404', | ||||
msg: 'NotFoundExc: Content with sha1_git checksum equals to ' + unarchivedRepo.readmeSha1git + ' not found!' | msg: 'NotFoundExc: Content with sha1_git checksum equals to ' + this.unarchivedRepo.content[0].sha1git + ' not found!' | ||||
}); | }); | ||||
}); | }); | ||||
it('should display NotFoundExc for unarchived directory sha1git', function() { | it('should display NotFoundExc for unarchived directory sha1git', function() { | ||||
const url = this.Urls.browse_directory(unarchivedRepo.rootDirSha1git); | const url = this.Urls.browse_directory(this.unarchivedRepo.rootDirectory); | ||||
urlShouldShowError(url, { | urlShouldShowError(url, { | ||||
code: '404', | code: '404', | ||||
msg: 'NotFoundExc: Directory with sha1_git ' + unarchivedRepo.rootDirSha1git + ' not found' | msg: 'NotFoundExc: Directory with sha1_git ' + this.unarchivedRepo.rootDirectory + ' not found' | ||||
}); | }); | ||||
}); | }); | ||||
it('should display NotFoundExc for unarchived revision sha1git', function() { | it('should display NotFoundExc for unarchived revision sha1git', function() { | ||||
const url = this.Urls.browse_revision(unarchivedRepo.revisionSha1git); | const url = this.Urls.browse_revision(this.unarchivedRepo.revision); | ||||
urlShouldShowError(url, { | urlShouldShowError(url, { | ||||
code: '404', | code: '404', | ||||
msg: 'NotFoundExc: Revision with sha1_git ' + unarchivedRepo.revisionSha1git + ' not found.' | msg: 'NotFoundExc: Revision with sha1_git ' + this.unarchivedRepo.revision + ' not found.' | ||||
}); | }); | ||||
}); | }); | ||||
it('should display NotFoundExc for unarchived snapshot sha1git', function() { | it('should display NotFoundExc for unarchived snapshot sha1git', function() { | ||||
const url = this.Urls.browse_snapshot(unarchivedRepo.snapshotSha1git); | const url = this.Urls.browse_snapshot(this.unarchivedRepo.snapshot); | ||||
urlShouldShowError(url, { | urlShouldShowError(url, { | ||||
code: '404', | code: '404', | ||||
msg: 'Snapshot with id ' + unarchivedRepo.snapshotSha1git + ' not found!' | msg: 'Snapshot with id ' + this.unarchivedRepo.snapshot + ' not found!' | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
context('For archived repositories', function() { | context('For archived repositories', function() { | ||||
before(function() { | before(function() { | ||||
const url = this.Urls.browse_origin_directory(archivedRepo.url); | const url = this.Urls.browse_origin_directory(origin.url); | ||||
cy.visit(url); | cy.visit(url); | ||||
cy.window().then(async win => { | |||||
const metadata = win.swh.webapp.getBrowsedSwhObjectMetadata(); | |||||
const apiUrl = Cypress.config().baseUrl + this.Urls.api_1_directory(metadata.directory); | |||||
const dirContent = await httpGetJson(apiUrl); | |||||
archivedRepo.contentSha1git = dirContent.find(x => x.type === 'file').checksums.sha1_git; | |||||
archivedRepo.directorySha1git = metadata.directory; | |||||
}); | |||||
}); | }); | ||||
it('should display NotFoundExc for invalid directory from archived repo', function() { | it('should display NotFoundExc for invalid directory from archived repo', function() { | ||||
const rootDir = this.Urls.browse_origin_directory(archivedRepo.url); | const rootDir = this.Urls.browse_origin_directory(origin.url); | ||||
const subDir = rootDir + archivedRepo.invalidSubDir; | const subDir = rootDir + origin.invalidSubDir; | ||||
urlShouldShowError(subDir, { | urlShouldShowError(subDir, { | ||||
code: '404', | code: '404', | ||||
msg: 'NotFoundExc: Directory entry with path ' + | msg: 'NotFoundExc: Directory entry with path ' + | ||||
archivedRepo.invalidSubDir + ' from ' + | origin.invalidSubDir + ' from ' + | ||||
archivedRepo.directorySha1git + ' not found' | origin.rootDirectory + ' not found' | ||||
}); | }); | ||||
}); | }); | ||||
it(`should display NotFoundExc for incorrect origin_url | it(`should display NotFoundExc for incorrect origin_url | ||||
with correct content hash`, function() { | with correct content hash`, function() { | ||||
const url = this.Urls.browse_content(`sha1_git:${archivedRepo.contentSha1git}`) + | const url = this.Urls.browse_content(`sha1_git:${origin.content[0].sha1git}`) + | ||||
`?origin_url=${unarchivedRepo.url}`; | `?origin_url=${this.unarchivedRepo.url}`; | ||||
urlShouldShowError(url, { | urlShouldShowError(url, { | ||||
code: '404', | code: '404', | ||||
msg: 'The Software Heritage archive has a content ' + | msg: 'The Software Heritage archive has a content ' + | ||||
'with the hash you provided but the origin ' + | 'with the hash you provided but the origin ' + | ||||
'mentioned in your request appears broken: ' + | 'mentioned in your request appears broken: ' + | ||||
unarchivedRepo.url + '. ' + | this.unarchivedRepo.url + '. ' + | ||||
'Please check the URL and try again.\n\n' + | 'Please check the URL and try again.\n\n' + | ||||
'Nevertheless, you can still browse the content ' + | 'Nevertheless, you can still browse the content ' + | ||||
'without origin information: ' + | 'without origin information: ' + | ||||
'/browse/content/sha1_git:' + | '/browse/content/sha1_git:' + | ||||
archivedRepo.contentSha1git + '/' | origin.content[0].sha1git + '/' | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
context('For invalid data', function() { | context('For invalid data', function() { | ||||
it(`should display 400 for invalid checksum for | it(`should display 400 for invalid checksum for | ||||
directory, snapshot, revision, content`, function() { | directory, snapshot, revision, content`, function() { | ||||
const types = ['directory', 'snapshot', 'revision', 'content']; | const types = ['directory', 'snapshot', 'revision', 'content']; | ||||
Show All 19 Lines |