Added RefreshCellularPlans support (#809)

This commit is contained in:
Ayush Sharma
2022-03-20 02:55:15 +05:30
committed by GitHub
parent 1f44de09b5
commit 96e15ff9f2
11 changed files with 746 additions and 573 deletions

View File

@@ -68,6 +68,7 @@ type Command struct {
ScheduleOSUpdateScan *ScheduleOSUpdateScan
ActiveNSExtensions *ActiveNSExtensions
RotateFileVaultKey *RotateFileVaultKey
RefreshCellularPlans *RefreshCellularPlans
}
// InstallProfile is an InstallProfile MDM Command
@@ -307,3 +308,7 @@ type FileVaultUnlock struct {
PrivateKeyExport []byte `plist:",omitempty" json:"private_key_export,omitempty"`
PrivateKeyExportPassword string `plist:",omitempty" json:"private_key_export_password,omitempty"`
}
type RefreshCellularPlans struct {
EsimServerUrl string `plist:"eSIMServerURL,omitempty" json:"esim_server_url,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -73,6 +73,7 @@ message Command {
SetBootstrapToken set_bootstrap_token = 37;
SetRecoveryLock set_recovery_lock = 38;
VerifyRecoveryLock verify_recovery_lock = 39;
RefreshCellularPlans refresh_cellular_plans = 40;
}
}
@@ -451,3 +452,7 @@ message ErrorChain {
string error_domain = 3;
int32 error_code = 4;
}
message RefreshCellularPlans {
string esim_server_url = 1;
}

View File

@@ -367,6 +367,15 @@ func (c *Command) MarshalJSON() ([]byte, error) {
RotateFileVaultKey: c.RotateFileVaultKey,
}
return json.Marshal(&x)
case "RefreshCellularPlans":
var x = struct {
RequestType string `json:"request_type"`
*RefreshCellularPlans
}{
RequestType: c.RequestType,
RefreshCellularPlans: c.RefreshCellularPlans,
}
return json.Marshal(&x)
default:
return nil, fmt.Errorf("mdm: unknown RequestType: %s", c.RequestType)
}

View File

@@ -343,6 +343,14 @@ func (c *Command) MarshalPlist() (interface{}, error) {
RequestType: c.RequestType,
RotateFileVaultKey: c.RotateFileVaultKey,
}, nil
case "RefreshCellularPlans":
return &struct {
RequestType string
*RefreshCellularPlans
}{
RequestType: c.RequestType,
RefreshCellularPlans: c.RefreshCellularPlans,
}, nil
default:
return nil, fmt.Errorf("mdm: unknown command RequestType, %s", c.RequestType)
}

View File

@@ -403,6 +403,12 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) {
},
},
}
case "RefreshCellularPlans":
cmdproto.Request = &mdmproto.Command_RefreshCellularPlans{
RefreshCellularPlans: &mdmproto.RefreshCellularPlans{
EsimServerUrl: cmd.RefreshCellularPlans.EsimServerUrl,
},
}
default:
return nil, fmt.Errorf("unknown command type %s", cmd.RequestType)
}

View File

@@ -138,6 +138,14 @@ func TestMarshalCommand(t *testing.T) {
},
},
},
{
Command: Command{
RequestType: "RefreshCellularPlans",
RefreshCellularPlans: &RefreshCellularPlans{
EsimServerUrl: "example.server.com",
},
},
},
}
for _, tt := range tests {
t.Run(tt.Command.RequestType+"_json", func(t *testing.T) {
@@ -500,6 +508,23 @@ func TestEndToEnd(t *testing.T) {
}
},
},
{
name: "RefreshCellularPlans",
requestBytes: []byte(
`{"request_type":"RefreshCellularPlans","esim_server_url":"example.server.com"}`,
),
testFn: func(t *testing.T, parts endToEndParts) {
needToSee := [][]byte{
[]byte(`eSIMServerURL`),
[]byte(`example.server.com`),
}
for _, b := range needToSee {
if !bytes.Contains(parts.plistData, b) {
t.Error(fmt.Sprintf("marshaled plist does not contain required bytes: '%s'", string(b)))
}
}
},
},
}
for _, tt := range tests {

View File

@@ -313,6 +313,13 @@ func (c *Command) UnmarshalJSON(data []byte) error {
}
c.RotateFileVaultKey = &payload
return nil
case "RefreshCellularPlans":
var payload RefreshCellularPlans
if err := json.Unmarshal(data, &payload); err != nil {
return errors.Wrapf(err, "mdm: unmarshal %s command json", c.RequestType)
}
c.RefreshCellularPlans = &payload
return nil
default:
return fmt.Errorf("mdm: unknown RequestType: %s", c.RequestType)
}

View File

@@ -297,6 +297,13 @@ func (c *Command) UnmarshalPlist(unmarshal func(i interface{}) error) error {
}
c.RotateFileVaultKey = &payload
return nil
case "RefreshCellularPlans":
var payload RefreshCellularPlans
if err := unmarshal(&payload); err != nil {
return errors.Wrapf(err, "mdm: unmarshal %s command plist", requestType.RequestType)
}
c.RefreshCellularPlans = &payload
return nil
default:
return fmt.Errorf("mdm: unknown RequestType: %s", requestType.RequestType)
}

View File

@@ -364,7 +364,11 @@ func protoToCommand(pb *mdmproto.Command) *Command {
PrivateKeyExportPassword: fvunlock.GetPrivateKeyExportPassword(),
},
}
case "RefreshCellularPlans":
pbc := pb.GetRefreshCellularPlans()
cmd.RefreshCellularPlans = &RefreshCellularPlans{
EsimServerUrl: pbc.GetEsimServerUrl(),
}
}
return &cmd
}

View File

@@ -0,0 +1,12 @@
#!/bin/bash
source $MICROMDM_ENV_PATH
endpoint="v1/commands"
jq -n \
--arg request_type "RefreshCellularPlans" \
--arg udid "$1" \
--arg esim_server_url $2 \
'.udid = $udid
|.esim_server_url = $esim_server_url
|.request_type = $request_type
'|\
curl $CURL_OPTS -K <(cat <<< "-u micromdm:$API_TOKEN") "$SERVER_URL/$endpoint" -d@-