Skip to content

[skip changelog] Do not allow extra paths in "archiveFileName" property in package_index.json #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Resource: increase code coverage
  • Loading branch information
cmaglie committed Aug 1, 2020
commit 7f64261cb0d1de0df7be5f2193012b79e33bac6f
10 changes: 5 additions & 5 deletions arduino/resources/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func (r *DownloadResource) IsCached(downloadDir *paths.Path) (bool, error) {

// Download a DownloadResource.
func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.Config) (*downloader.Downloader, error) {
path, err := r.ArchivePath(downloadDir)
if err != nil {
return nil, fmt.Errorf("getting archive path: %s", err)
}

cached, err := r.TestLocalArchiveIntegrity(downloadDir)
if err != nil {
return nil, fmt.Errorf("testing local archive integrity: %s", err)
Expand All @@ -61,11 +66,6 @@ func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.
return nil, nil
}

path, err := r.ArchivePath(downloadDir)
if err != nil {
return nil, fmt.Errorf("getting archive path: %s", err)
}

if stats, err := path.Stat(); os.IsNotExist(err) {
// normal download
} else if err == nil && stats.Size() > r.Size {
Expand Down
23 changes: 23 additions & 0 deletions arduino/resources/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ func TestResourcesSanityChecks(t *testing.T) {
}
}

func TestResourceErrorHandling(t *testing.T) {
tmp, err := paths.MkTempDir("", "")
require.NoError(t, err)
defer tmp.RemoveAll()

r := &DownloadResource{
ArchiveFileName: "..",
CachePath: "cache",
}

c, err := r.IsCached(tmp)
require.Error(t, err)
require.False(t, c)

d, err := r.Download(tmp, nil)
require.Error(t, err)
require.Nil(t, d)

e, err := r.TestLocalArchiveIntegrity(tmp)
require.Error(t, err)
require.False(t, e)
}

func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) {
goldUserAgentValue := fmt.Sprintf("arduino-cli/0.0.0-test.preview (amd64; linux; go1.12.4) Commit:deadbeef/Build:2019-06-12 11:11:11.111")
goldUserAgentString := "User-Agent: " + goldUserAgentValue
Expand Down