Merge pull request #21 from marineam/trivial
protocol: style fix, use "ID" and "SHA" in identifiers.
This commit is contained in:
commit
3d5d24e0b8
10 changed files with 51 additions and 51 deletions
|
@ -150,8 +150,8 @@ const (
|
||||||
// Standard values
|
// Standard values
|
||||||
AppOK AppStatus = "ok"
|
AppOK AppStatus = "ok"
|
||||||
AppRestricted AppStatus = "restricted"
|
AppRestricted AppStatus = "restricted"
|
||||||
AppUnknownId AppStatus = "error-unknownApplication"
|
AppUnknownID AppStatus = "error-unknownApplication"
|
||||||
AppInvalidId AppStatus = "error-invalidAppId"
|
AppInvalidID AppStatus = "error-invalidAppId"
|
||||||
|
|
||||||
// Extra error values
|
// Extra error values
|
||||||
AppInvalidVersion AppStatus = "error-invalidVersion"
|
AppInvalidVersion AppStatus = "error-invalidVersion"
|
||||||
|
|
|
@ -87,13 +87,13 @@ func (o *OmahaHandler) ServeHTTP(w http.ResponseWriter, httpReq *http.Request) {
|
||||||
func (o *OmahaHandler) serveApp(omahaResp *Response, httpReq *http.Request, omahaReq *Request, appReq *AppRequest) *AppResponse {
|
func (o *OmahaHandler) serveApp(omahaResp *Response, httpReq *http.Request, omahaReq *Request, appReq *AppRequest) *AppResponse {
|
||||||
if err := o.CheckApp(omahaReq, appReq); err != nil {
|
if err := o.CheckApp(omahaReq, appReq); err != nil {
|
||||||
if appStatus, ok := err.(AppStatus); ok {
|
if appStatus, ok := err.(AppStatus); ok {
|
||||||
return omahaResp.AddApp(appReq.Id, appStatus)
|
return omahaResp.AddApp(appReq.ID, appStatus)
|
||||||
}
|
}
|
||||||
log.Printf("omaha: CheckApp failed: %v", err)
|
log.Printf("omaha: CheckApp failed: %v", err)
|
||||||
return omahaResp.AddApp(appReq.Id, AppInternalError)
|
return omahaResp.AddApp(appReq.ID, AppInternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
appResp := omahaResp.AddApp(appReq.Id, AppOK)
|
appResp := omahaResp.AddApp(appReq.ID, AppOK)
|
||||||
if appReq.UpdateCheck != nil {
|
if appReq.UpdateCheck != nil {
|
||||||
o.checkUpdate(appResp, httpReq, omahaReq, appReq)
|
o.checkUpdate(appResp, httpReq, omahaReq, appReq)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
testAppId = "{27BD862E-8AE8-4886-A055-F7F1A6460627}"
|
testAppID = "{27BD862E-8AE8-4886-A055-F7F1A6460627}"
|
||||||
testAppVer = "1.0.0"
|
testAppVer = "1.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
nilRequest = NewRequest()
|
nilRequest = NewRequest()
|
||||||
nilRequest.AddApp(testAppId, testAppVer)
|
nilRequest.AddApp(testAppID, testAppVer)
|
||||||
nilResponse = NewResponse()
|
nilResponse = NewResponse()
|
||||||
nilResponse.AddApp(testAppId, AppOK)
|
nilResponse.AddApp(testAppID, AppOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareXML(a, b interface{}) error {
|
func compareXML(a, b interface{}) error {
|
||||||
|
|
|
@ -32,8 +32,8 @@ var (
|
||||||
// Package represents a single downloadable file.
|
// Package represents a single downloadable file.
|
||||||
type Package struct {
|
type Package struct {
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
Sha1 string `xml:"hash,attr"`
|
SHA1 string `xml:"hash,attr"`
|
||||||
Sha256 string `xml:"hash_sha256,attr,omitempty"`
|
SHA256 string `xml:"hash_sha256,attr,omitempty"`
|
||||||
Size uint64 `xml:"size,attr"`
|
Size uint64 `xml:"size,attr"`
|
||||||
Required bool `xml:"required,attr"`
|
Required bool `xml:"required,attr"`
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ func (p *Package) FromReader(r io.Reader) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Sha1 = sha1b64
|
p.SHA1 = sha1b64
|
||||||
p.Sha256 = sha256b64
|
p.SHA256 = sha256b64
|
||||||
p.Size = uint64(n)
|
p.Size = uint64(n)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -86,12 +86,12 @@ func (p *Package) VerifyReader(r io.Reader) error {
|
||||||
return PackageSizeMismatchError
|
return PackageSizeMismatchError
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Sha1 != sha1b64 {
|
if p.SHA1 != sha1b64 {
|
||||||
return PackageHashMismatchError
|
return PackageHashMismatchError
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow Sha256 to be empty since it is a protocol extension.
|
// Allow SHA256 to be empty since it is a later protocol addition.
|
||||||
if p.Sha256 != "" && p.Sha256 != sha256b64 {
|
if p.SHA256 != "" && p.SHA256 != sha256b64 {
|
||||||
return PackageHashMismatchError
|
return PackageHashMismatchError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ import (
|
||||||
func TestPackageFromPath(t *testing.T) {
|
func TestPackageFromPath(t *testing.T) {
|
||||||
expect := Package{
|
expect := Package{
|
||||||
Name: "null",
|
Name: "null",
|
||||||
Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
||||||
Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
||||||
Size: 0,
|
Size: 0,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ func TestProtocolFromReader(t *testing.T) {
|
||||||
data := strings.NewReader("testing\n")
|
data := strings.NewReader("testing\n")
|
||||||
expect := Package{
|
expect := Package{
|
||||||
Name: "",
|
Name: "",
|
||||||
Sha1: "mAFznarkTsUpPU4fU9P00tQm2Rw=",
|
SHA1: "mAFznarkTsUpPU4fU9P00tQm2Rw=",
|
||||||
Sha256: "EqYfThc/s6EcBdZHH3Ryj3YjG0pfzZZnzvOvh6OuTcI=",
|
SHA256: "EqYfThc/s6EcBdZHH3Ryj3YjG0pfzZZnzvOvh6OuTcI=",
|
||||||
Size: 8,
|
Size: 8,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,8 @@ func TestProtocolFromReader(t *testing.T) {
|
||||||
func TestPackageVerify(t *testing.T) {
|
func TestPackageVerify(t *testing.T) {
|
||||||
p := Package{
|
p := Package{
|
||||||
Name: "null",
|
Name: "null",
|
||||||
Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
||||||
Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
||||||
Size: 0,
|
Size: 0,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
|
@ -74,11 +74,11 @@ func TestPackageVerify(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPackageVerifyNoSha256(t *testing.T) {
|
func TestPackageVerifyNoSHA256(t *testing.T) {
|
||||||
p := Package{
|
p := Package{
|
||||||
Name: "null",
|
Name: "null",
|
||||||
Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
||||||
Sha256: "",
|
SHA256: "",
|
||||||
Size: 0,
|
Size: 0,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,8 @@ func TestPackageVerifyNoSha256(t *testing.T) {
|
||||||
func TestPackageVerifyBadSize(t *testing.T) {
|
func TestPackageVerifyBadSize(t *testing.T) {
|
||||||
p := Package{
|
p := Package{
|
||||||
Name: "null",
|
Name: "null",
|
||||||
Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
||||||
Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
||||||
Size: 1,
|
Size: 1,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
|
@ -107,11 +107,11 @@ func TestPackageVerifyBadSize(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPackageVerifyBadSha1(t *testing.T) {
|
func TestPackageVerifyBadSHA1(t *testing.T) {
|
||||||
p := Package{
|
p := Package{
|
||||||
Name: "null",
|
Name: "null",
|
||||||
Sha1: "xxxxxxxxxxxxxxxxxxxxxxxxxxx=",
|
SHA1: "xxxxxxxxxxxxxxxxxxxxxxxxxxx=",
|
||||||
Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
|
||||||
Size: 0,
|
Size: 0,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
|
@ -125,11 +125,11 @@ func TestPackageVerifyBadSha1(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPackageVerifyBadSha256(t *testing.T) {
|
func TestPackageVerifyBadSHA256(t *testing.T) {
|
||||||
p := Package{
|
p := Package{
|
||||||
Name: "null",
|
Name: "null",
|
||||||
Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
|
||||||
Sha256: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=",
|
SHA256: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=",
|
||||||
Size: 0,
|
Size: 0,
|
||||||
Required: false,
|
Required: false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,10 @@ type Request struct {
|
||||||
Protocol string `xml:"protocol,attr"`
|
Protocol string `xml:"protocol,attr"`
|
||||||
InstallSource string `xml:"installsource,attr,omitempty"`
|
InstallSource string `xml:"installsource,attr,omitempty"`
|
||||||
IsMachine string `xml:"ismachine,attr,omitempty"`
|
IsMachine string `xml:"ismachine,attr,omitempty"`
|
||||||
RequestId string `xml:"requestid,attr,omitempty"`
|
RequestID string `xml:"requestid,attr,omitempty"`
|
||||||
SessionId string `xml:"sessionid,attr,omitempty"`
|
SessionID string `xml:"sessionid,attr,omitempty"`
|
||||||
TestSource string `xml:"testsource,attr,omitempty"`
|
TestSource string `xml:"testsource,attr,omitempty"`
|
||||||
UserId string `xml:"userid,attr,omitempty"`
|
UserID string `xml:"userid,attr,omitempty"`
|
||||||
Version string `xml:"version,attr,omitempty"`
|
Version string `xml:"version,attr,omitempty"`
|
||||||
|
|
||||||
// update engine extension, duplicates the version attribute.
|
// update engine extension, duplicates the version attribute.
|
||||||
|
@ -57,7 +57,7 @@ func NewRequest() *Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) AddApp(id, version string) *AppRequest {
|
func (r *Request) AddApp(id, version string) *AppRequest {
|
||||||
a := &AppRequest{Id: id, Version: version}
|
a := &AppRequest{ID: id, Version: version}
|
||||||
r.Apps = append(r.Apps, a)
|
r.Apps = append(r.Apps, a)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ type AppRequest struct {
|
||||||
Ping *PingRequest `xml:"ping"`
|
Ping *PingRequest `xml:"ping"`
|
||||||
UpdateCheck *UpdateRequest `xml:"updatecheck"`
|
UpdateCheck *UpdateRequest `xml:"updatecheck"`
|
||||||
Events []*EventRequest `xml:"event" json:",omitempty"`
|
Events []*EventRequest `xml:"event" json:",omitempty"`
|
||||||
Id string `xml:"appid,attr,omitempty"`
|
ID string `xml:"appid,attr,omitempty"`
|
||||||
Client string `xml:"client,attr,omitempty"`
|
Client string `xml:"client,attr,omitempty"`
|
||||||
InstallAge string `xml:"installage,attr,omitempty"`
|
InstallAge string `xml:"installage,attr,omitempty"`
|
||||||
Lang string `xml:"lang,attr,omitempty"`
|
Lang string `xml:"lang,attr,omitempty"`
|
||||||
|
@ -81,7 +81,7 @@ type AppRequest struct {
|
||||||
|
|
||||||
// coreos update engine extensions
|
// coreos update engine extensions
|
||||||
AlephVersion string `xml:"alephversion,attr,omitempty"`
|
AlephVersion string `xml:"alephversion,attr,omitempty"`
|
||||||
BootId string `xml:"bootid,attr,omitempty"`
|
BootID string `xml:"bootid,attr,omitempty"`
|
||||||
MachineID string `xml:"machineid,attr,omitempty"`
|
MachineID string `xml:"machineid,attr,omitempty"`
|
||||||
OEM string `xml:"oem,attr,omitempty"`
|
OEM string `xml:"oem,attr,omitempty"`
|
||||||
OEMVersion string `xml:"oemversion,attr,omitempty"`
|
OEMVersion string `xml:"oemversion,attr,omitempty"`
|
||||||
|
@ -143,7 +143,7 @@ type DayStart struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Response) AddApp(id string, status AppStatus) *AppResponse {
|
func (r *Response) AddApp(id string, status AppStatus) *AppResponse {
|
||||||
a := &AppResponse{Id: id, Status: status}
|
a := &AppResponse{ID: id, Status: status}
|
||||||
r.Apps = append(r.Apps, a)
|
r.Apps = append(r.Apps, a)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ type AppResponse struct {
|
||||||
Ping *PingResponse `xml:"ping"`
|
Ping *PingResponse `xml:"ping"`
|
||||||
UpdateCheck *UpdateResponse `xml:"updatecheck"`
|
UpdateCheck *UpdateResponse `xml:"updatecheck"`
|
||||||
Events []*EventResponse `xml:"event" json:",omitempty"`
|
Events []*EventResponse `xml:"event" json:",omitempty"`
|
||||||
Id string `xml:"appid,attr,omitempty"`
|
ID string `xml:"appid,attr,omitempty"`
|
||||||
Status AppStatus `xml:"status,attr,omitempty"`
|
Status AppStatus `xml:"status,attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ type Action struct {
|
||||||
|
|
||||||
// update engine extensions for event="postinstall"
|
// update engine extensions for event="postinstall"
|
||||||
DisplayVersion string `xml:"DisplayVersion,attr,omitempty"`
|
DisplayVersion string `xml:"DisplayVersion,attr,omitempty"`
|
||||||
Sha256 string `xml:"sha256,attr,omitempty"`
|
SHA256 string `xml:"sha256,attr,omitempty"`
|
||||||
NeedsAdmin bool `xml:"needsadmin,attr,omitempty"`
|
NeedsAdmin bool `xml:"needsadmin,attr,omitempty"`
|
||||||
IsDeltaPayload bool `xml:"IsDeltaPayload,attr,omitempty"`
|
IsDeltaPayload bool `xml:"IsDeltaPayload,attr,omitempty"`
|
||||||
DisablePayloadBackoff bool `xml:"DisablePayloadBackoff,attr,omitempty"`
|
DisablePayloadBackoff bool `xml:"DisablePayloadBackoff,attr,omitempty"`
|
||||||
|
|
|
@ -39,16 +39,16 @@ func TestOmahaRequestUpdateCheck(t *testing.T) {
|
||||||
t.Error("Unexpected version", v.OS.Version)
|
t.Error("Unexpected version", v.OS.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Apps[0].Id != "{87efface-864d-49a5-9bb3-4b050a7c227a}" {
|
if v.Apps[0].ID != "{87efface-864d-49a5-9bb3-4b050a7c227a}" {
|
||||||
t.Error("Expected an App Id")
|
t.Error("Expected an App ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Apps[0].BootId != "{7D52A1CC-7066-40F0-91C7-7CB6A871BFDE}" {
|
if v.Apps[0].BootID != "{7D52A1CC-7066-40F0-91C7-7CB6A871BFDE}" {
|
||||||
t.Error("Expected a Boot Id")
|
t.Error("Expected a Boot ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Apps[0].MachineID != "{8BDE4C4D-9083-4D61-B41C-3253212C0C37}" {
|
if v.Apps[0].MachineID != "{8BDE4C4D-9083-4D61-B41C-3253212C0C37}" {
|
||||||
t.Error("Expected a MachineId")
|
t.Error("Expected a Machine ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Apps[0].OEM != "ec3000" {
|
if v.Apps[0].OEM != "ec3000" {
|
||||||
|
@ -88,13 +88,13 @@ func ExampleNewResponse() {
|
||||||
u.AddURL("http://localhost/updates")
|
u.AddURL("http://localhost/updates")
|
||||||
m := u.AddManifest("9999.0.0")
|
m := u.AddManifest("9999.0.0")
|
||||||
k := m.AddPackage()
|
k := m.AddPackage()
|
||||||
k.Sha1 = "+LXvjiaPkeYDLHoNKlf9qbJwvnk="
|
k.SHA1 = "+LXvjiaPkeYDLHoNKlf9qbJwvnk="
|
||||||
k.Name = "update.gz"
|
k.Name = "update.gz"
|
||||||
k.Size = 67546213
|
k.Size = 67546213
|
||||||
k.Required = true
|
k.Required = true
|
||||||
a := m.AddAction("postinstall")
|
a := m.AddAction("postinstall")
|
||||||
a.DisplayVersion = "9999.0.0"
|
a.DisplayVersion = "9999.0.0"
|
||||||
a.Sha256 = "0VAlQW3RE99SGtSB5R4m08antAHO8XDoBMKDyxQT/Mg="
|
a.SHA256 = "0VAlQW3RE99SGtSB5R4m08antAHO8XDoBMKDyxQT/Mg="
|
||||||
a.NeedsAdmin = false
|
a.NeedsAdmin = false
|
||||||
a.IsDeltaPayload = true
|
a.IsDeltaPayload = true
|
||||||
a.DisablePayloadBackoff = true
|
a.DisablePayloadBackoff = true
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (ts *TrivialServer) AddPackage(file, name string) error {
|
||||||
if len(ts.tu.Manifest.Actions) == 0 {
|
if len(ts.tu.Manifest.Actions) == 0 {
|
||||||
act := ts.tu.Manifest.AddAction("postinstall")
|
act := ts.tu.Manifest.AddAction("postinstall")
|
||||||
act.DisablePayloadBackoff = true
|
act.DisablePayloadBackoff = true
|
||||||
act.Sha256 = pkg.Sha256
|
act.SHA256 = pkg.SHA256
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.Mux.Handle(pkg_prefix+name, &trivialHandler{file})
|
ts.Mux.Handle(pkg_prefix+name, &trivialHandler{file})
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
func mkUpdateReq() (*bytes.Buffer, error) {
|
func mkUpdateReq() (*bytes.Buffer, error) {
|
||||||
req := NewRequest()
|
req := NewRequest()
|
||||||
app := req.AddApp(testAppId, testAppVer)
|
app := req.AddApp(testAppID, testAppVer)
|
||||||
app.AddUpdateCheck()
|
app.AddUpdateCheck()
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
// existing install. The application id may not be blank.
|
// existing install. The application id may not be blank.
|
||||||
type Update struct {
|
type Update struct {
|
||||||
XMLName xml.Name `xml:"update" json:"-"`
|
XMLName xml.Name `xml:"update" json:"-"`
|
||||||
Id string `xml:"appid,attr"`
|
ID string `xml:"appid,attr"`
|
||||||
PreviousVersion string `xml:"previousversion,attr,omitempty"`
|
PreviousVersion string `xml:"previousversion,attr,omitempty"`
|
||||||
URL URL `xml:"urls>url"`
|
URL URL `xml:"urls>url"`
|
||||||
Manifest
|
Manifest
|
||||||
|
|
Loading…
Add table
Reference in a new issue