Skip to content

validate hostname when cloning a URL - #5200

Merged
iAmWillShepherd merged 12 commits into
masterfrom
stub-behaviour-for-testing
Sep 6, 2018
Merged

iAmWillShepherd merged 12 commits into
masterfrom
stub-behaviour-for-testing

Conversation

@shiftkey

@shiftkey shiftkey commented Jul 19, 2018 •

Copy link
Copy Markdown
Member

Supersedes #4362

Fixes #4154

This PR addresses two related issues:

  • what's a sane way to test findAccountForRemoteURL even though it needs to access the API?
  • can we fix the original bug that was the inspiration for digging into this whole area?

For the first part, I changed the signature to findAccountForRemoteURL so that you can pass it a different implementation, to test whether a repository is accessible for that account.

This meant I could stub out the tests to fail unless certain criteria was met:

const mockCanAccessRepository = (
  account: Account,
  owner: string,
  name: string
) => {
  // private repository, only this person can access it
  if (
    account.endpoint === getDotComAPIEndpoint() &&
    account.login === 'joan' &&
    owner === 'desktop' &&
    name === 'repo-fixture'
  ) {
    return Promise.resolve(true)
  }

  // public repository is accessible to everyone
  if (
    account.endpoint === getDotComAPIEndpoint() &&
    owner === 'inkscape' &&
    name === 'inkscape'
  ) {
    return Promise.resolve(true)
  }

  return Promise.resolve(false)
}

I also took some time in there to simplify the internals of findAccountForRemoteURL.

For the second part of the issue, I took a different approach to what @JordanMussi did in #4154:

  • return hostname from parseRepositoryIdentifier if it was found, or null otherwise
  • if hostname is not set, stick to the current behaviour and probe
  • if hostname is set, ensure that the hostname associated with the account matches the hostname, otherwise this is a domain mismatch

TODO:

  • test with GitLab repository (full URL) resolves correctly
  • test with GitHub account to ensure valid public repositories (both full URL or owner/name alias) resolve correctly
  • test with GitHub account to ensure valid private repositories (both full URL or owner/name alias) resolve correctly
  • test with GHE account to ensure valid repositories (both full URL or owner/name alias) resolve correctly

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 13, 2018
@shiftkey shiftkey modified the milestones: 1.3.5, 1.4.0 Aug 31, 2018
@iAmWillShepherd iAmWillShepherd self-assigned this Sep 5, 2018

@iAmWillShepherd iAmWillShepherd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question

Comment thread app/src/lib/find-account.ts Resolved
@outofambit
outofambit self-requested a review September 5, 2018 19:38
@iAmWillShepherd
iAmWillShepherd merged commit 386261c into master Sep 6, 2018
@iAmWillShepherd
iAmWillShepherd deleted the stub-behaviour-for-testing branch September 6, 2018 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants