Skip to content

Commit

Permalink
fix: Logic with accessType and tests for private repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Aug 26, 2019
1 parent 1bb96ed commit 95c7036
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
20 changes: 3 additions & 17 deletions src/detectors/ScanningStrategyDetector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,9 @@ describe('ScanningStrategyDetector', () => {
};
});

const container = createTestContainer({ uri: '/local/path', auth: 'auth' });
const container = createTestContainer({ uri: '/local/path', auth: 'bad AT' });

const result = await container.scanningStrategyDetector.detect();

expect(result).toEqual({
accessType: AccessType.private,
localPath: '/local/path',
remoteUrl: repoPath,
serviceType: ServiceType.github,
});
await expect(container.scanningStrategyDetector.detect()).rejects.toThrow('bad credentials');
});

it('remote public GitHub', async () => {
Expand Down Expand Up @@ -106,14 +99,7 @@ describe('ScanningStrategyDetector', () => {
.reply(404);
const container = createTestContainer({ uri: repoPath, auth: 'bad AT' });

const result = await container.scanningStrategyDetector.detect();

expect(result).toEqual({
accessType: AccessType.private,
localPath: undefined,
remoteUrl: repoPath,
serviceType: ServiceType.github,
});
await expect(container.scanningStrategyDetector.detect()).rejects.toThrow('bad credentials');
});

it('remote public GitHub without protocol in the URL', async () => {
Expand Down
10 changes: 2 additions & 8 deletions src/detectors/ScanningStrategyDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class ScanningStrategyDetector implements IDetector<string, ScanningStrat
const path = ScanningStrategyDetectorUtils.normalizePath(this.argumentsProvider.uri);

const inputType = this.determineInputType(path);

// try to determine remote origin if input is local file system
if (inputType === ServiceType.local) {
remoteService = await this.determineRemote(path);
Expand All @@ -41,10 +42,6 @@ export class ScanningStrategyDetector implements IDetector<string, ScanningStrat
accessType = await this.determineRemoteAccessType({ remoteUrl: path, serviceType });
}

if (accessType === AccessType.private && this.argumentsProvider.auth === undefined) {
throw new Error('AT was not provided');
}

return {
serviceType,
accessType,
Expand Down Expand Up @@ -78,10 +75,7 @@ export class ScanningStrategyDetector implements IDetector<string, ScanningStrat
try {
response = await this.gitHubClient.get(parsedUrl.owner, parsedUrl.name);
} catch (error) {
if (error.status && error.status === 404) {
return AccessType.private;
}
throw error;
throw ErrorFactory.newInternalError('You passed bad credentials or non existing repo.');
}

if (response.status === 200) {
Expand Down

0 comments on commit 95c7036

Please sign in to comment.