-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackager-windows_test.go
154 lines (137 loc) · 5.97 KB
/
packager-windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"bytes"
"fmt"
"github.com/fipress/fiputil"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"html/template"
"io/ioutil"
"regexp"
"testing"
)
func TestBuildProvider(t *testing.T) {
//s:= `/c chcp 65001 & "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64&& cl /EHsc /MT /favor:blend /std:c++17 /await /c C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test/windows/provider_windows.h&& link /dll provider_windows.obj /MACHINE:X64 /out:C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test/windows/provider_windows.dll"user32.lib"`
//s:= `@call "%C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 %* && cl /EHsc /MT /favor:blend /std:c++17 /await /c "C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\windows\provider_windows.cpp" && link /dll provider_windows.obj /MACHINE:X64 /out:"C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\windows\provider_windows.dll user32.lib`
//c1 := `C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat`
cmd := NewCommand(`C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\windows\build.bat`)
cmd.Dir = `C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\windows\`
buf := new(bytes.Buffer)
err := cmd.RunEx(buf, buf, 0)
t.Log(err)
reader := transform.NewReader(buf, simplifiedchinese.GBK.NewDecoder())
d, e := ioutil.ReadAll(reader)
t.Log(string(d), e)
fiputil.CopyFile(`C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\windows\provider_windows.dll`, `C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\build\windows\temp\provider_windows.dll`)
}
func TestBuild(t *testing.T) {
executable := `C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\build\windows\temp\t1.exe`
b := builder{output: executable, dir: `C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\`}
envStr := fmt.Sprintf(`CGO_LDFLAGS=-static %s`, `C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\build\windows\temp\provider_windows.dll`)
debug("env:", envStr)
b.addEnv(envStr)
b.build()
/*cmd := NewCommand("go","build","-o", executable)
cmd.Dir = `C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\`
buf := new(bytes.Buffer)
err := cmd.RunEx(buf,buf,0)
if err != nil {
fatal("Build exe for windows failed, error:", err)
}
reader:=transform.NewReader(buf,simplifiedchinese.GBK.NewDecoder())
d,e := ioutil.ReadAll(reader)
t.Log(string(d),e)*/
}
func TestPack(t *testing.T) {
cmd := NewCommand(`C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64\MakeAppx.exe`, "pack", "/v", "/d",
`C:\mayunfeng\projects\go\src\github.com\fipress\demo\build\windows\temp`,
"/p", `C:\mayunfeng\projects\go\src\github.com\fipress\demo\build\windows\testdemo.msix`)
//cmd.Dir = wp.outputDir
buf := new(bytes.Buffer)
err := cmd.RunEx(buf, buf, 0)
if err != nil {
fatal("Build exe for windows failed, error:", err)
}
reader := transform.NewReader(buf, simplifiedchinese.GBK.NewDecoder())
d, e := ioutil.ReadAll(reader)
t.Log(string(d), e)
}
//SignTool sign /fd <Hash Algorithm> /a /f <Path to Certificate>.pfx /p <Your Password> <File path>.msix
func TestSign(t *testing.T) {
cmd := NewCommand(`C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64\signtool.exe`,
`sign`, `/fd`, `SHA256`, `/t`, `http://timestamp.verisign.com/scripts/timestamp.dll`,
`/a`, `/f`, `C:\dcn\c1.pfx`, `/p`, `123456`, `testdemo.msix`)
cmd.Dir = `C:\mayunfeng\projects\go\src\github.com\fipress\GoUI-cli\test\build\windows\`
buf := new(bytes.Buffer)
err := cmd.RunEx(buf, buf, 0)
t.Log(err)
reader := transform.NewReader(buf, simplifiedchinese.GBK.NewDecoder())
d, e := ioutil.ReadAll(reader)
t.Log(string(d), e)
}
func TestCert(t *testing.T) {
cmd := NewCommand(`powershell.exe`, "New-SelfSignedCertificate", "-Type", "Custom",
"-Subject", `"CN=FIPress, O=FIP, L=Beijing, C=CN"`,
"-KeyUsage", "DigitalSignature",
"-FriendlyName", `"TF"`, "-CertStoreLocation",
`"Cert:\CurrentUser\My"`,
"-TextExtension", ` @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")`)
//cmd.Dir = wp.outputDir
buf := new(bytes.Buffer)
err := cmd.RunEx(buf, nil, 0)
t.Log(err)
regex := regexp.MustCompile(`\b[0-9a-fA-F]{40}\b`)
c := regex.Find(buf.Bytes())
t.Log("thumb:", c)
reader := transform.NewReader(buf, simplifiedchinese.GBK.NewDecoder())
d, e := ioutil.ReadAll(reader)
t.Log(string(d), e)
if err != nil {
fatal("gen key failed, error:", err)
}
t.Log("OK")
}
func TestExtract(t *testing.T) {
regex := regexp.MustCompile(`\b[0-9a-fA-F]{40}\b`)
c := regex.FindString(`PSParentPath:Microsoft.PowerShell.Security\Certificate::CurrentUser\My
Thumbprint Subject
---------- -------
46400A782BEA148E553FBF5B725C47D62EB17B78 CN=MyCompany, O=MyCompany, L=MyCity, S=MyState, C=MyCountry `)
t.Log("thumb:", c)
}
func TestExport(t *testing.T) {
cmd := NewCommand(`powershell.exe`, `$pwd = ConvertTo-SecureString -String 123456 -Force -AsPlainText
Export-PfxCertificate -cert "Cert:\CurrentUser\My\D3FDF04E7C87C1C07C14E1043A209F42C1179270" -FilePath C:\dcn\c1.pfx -Password $pwd`)
//cmd.Dir = wp.outputDir
buf := new(bytes.Buffer)
err := cmd.RunEx(buf, buf, 0)
t.Log(err)
reader := transform.NewReader(buf, simplifiedchinese.GBK.NewDecoder())
d, e := ioutil.ReadAll(reader)
t.Log(string(d), e)
if err != nil {
fatal("gen key failed, error:", err)
}
t.Log("OK")
}
func TestTemp(t *testing.T) {
type in struct {
Name string
}
type s2 struct {
*in
}
type s1 struct {
*s2
}
type s struct {
*s1
Age int
}
tmpl, err := template.New(`a`).Parse(`name:{{.Name}}, age:{{.Age}}`)
t.Log(err)
b := new(bytes.Buffer)
err = tmpl.Execute(b, s{&s1{&s2{&in{"A"}}}, 12})
t.Log(err)
t.Log(b.String())
}