Skip to content

Commit

Permalink
Fix android keystore path is not resolved correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lucor committed Dec 26, 2020
1 parent aea6085 commit d949bc3
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog - Fyne.io fyne-cross

## Unreleased
- Fix android keystore path is not resolved correctly

## [1.0.0]
- Add support for "fyne release" #3
- Add support for creating packaged .tar.gz bundles on freebsd #6
Expand Down
12 changes: 11 additions & 1 deletion internal/command/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package command
import (
"fmt"
"os"
"path"
"path/filepath"

"github.com/fyne-io/fyne-cross/internal/log"
Expand Down Expand Up @@ -187,7 +188,16 @@ func makeAndroidContext(flags *androidFlags, args []string) (Context, error) {
ctx.OS = androidOS
ctx.ID = androidOS

ctx.Keystore = flags.Keystore
if path.IsAbs(flags.Keystore) {
return Context{}, fmt.Errorf("keystore location must be relative to the project root: %s", ctx.Volume.WorkDirHost())
}

_, err = os.Stat(volume.JoinPathHost(ctx.Volume.WorkDirHost(), flags.Keystore))
if err != nil {
return Context{}, fmt.Errorf("keystore location must be under the project root: %s", ctx.Volume.WorkDirHost())
}

ctx.Keystore = volume.JoinPathContainer(ctx.Volume.WorkDirContainer(), flags.Keystore)
ctx.KeystorePass = flags.KeystorePass
ctx.KeyPass = flags.KeyPass

Expand Down
115 changes: 115 additions & 0 deletions internal/command/android_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package command

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_makeAndroidContext(t *testing.T) {
vol, err := mockDefaultVolume()
require.Nil(t, err)

type args struct {
flags *androidFlags
args []string
}
tests := []struct {
name string
args args
want Context
wantErr bool
}{
{
name: "keystore path must be relative to project root",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "/tmp/my.keystore",
},
},
want: Context{},
wantErr: true,
},
{
name: "keystore path does not exist",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "my.keystore",
},
},
want: Context{},
wantErr: true,
},
{
name: "default",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "testdata/my.keystore",
},
},
want: Context{
AppBuild: "1",
AppID: "test",
ID: androidOS,
OS: androidOS,
DockerImage: androidImage,
Volume: vol,
CacheEnabled: true,
StripDebug: true,
Package: ".",
Keystore: "/app/testdata/my.keystore",
},
wantErr: false,
},
{
name: "default",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "./testdata/my.keystore",
},
},
want: Context{
AppBuild: "1",
AppID: "test",
ID: androidOS,
OS: androidOS,
DockerImage: androidImage,
Volume: vol,
CacheEnabled: true,
StripDebug: true,
Package: ".",
Keystore: "/app/testdata/my.keystore",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, err := makeAndroidContext(tt.args.flags, tt.args.args)

if tt.wantErr {
require.NotNil(t, err)
return
}
require.Nil(t, err)
assert.Equal(t, tt.want, ctx)
})
}
}
1 change: 1 addition & 0 deletions internal/command/testdata/my.keystore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
4 changes: 2 additions & 2 deletions internal/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func Mount(workDirHost string, cacheDirHost string) (Volume, error) {
// JoinPathContainer joins any number of path elements into a single path,
// separating them with the Container OS specific Separator.
func JoinPathContainer(elem ...string) string {
return strings.Join(elem, "/")
return filepath.Clean(strings.Join(elem, "/"))
}

// JoinPathHost joins any number of path elements into a single path,
// separating them with the Host OS specific Separator.
func JoinPathHost(elem ...string) string {
return filepath.Join(elem...)
return filepath.Clean(filepath.Join(elem...))
}

// Zip compress the source file into a zip archive
Expand Down

0 comments on commit d949bc3

Please sign in to comment.