Commit 01e7aa56 authored by Yann Garcia's avatar Yann Garcia
Browse files

Bug fixed in meep-dai durng TTFT043 validation

parent 04a90cdb
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -608,6 +608,13 @@ func meAppListGET(w http.ResponseWriter, r *http.Request) {
	vendorId := q["vendorId"]
	serviceCont := q["serviceCont"]

	validParams := []string{"appName", "appProvider", "appSoftVersion", "vendorId", "serviceCont"}
	err := validateQueryParams(q, validParams)
	if err != nil {
		errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest)
		return
	}

	// log.Debug("meAppListGET: appName: ", appName)
	// log.Debug("meAppListGET: appProvider: ", appProvider)
	// log.Debug("meAppListGET: appSoftVersion: ", appSoftVersion)
@@ -710,6 +717,35 @@ func devAppContextsPOST(w http.ResponseWriter, r *http.Request) {
	}
	log.Info("devAppContextsPOST: ", appContext)

	// Sanity checks
	if appContext.ContextId != "" { // ETSI GS MEC 016 Clause 6.2.3 Type: AppContext.
		err = errors.New("ContextId shall not be set")
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	if appContext.AssociateDevAppId == "" { // ETSI GS MEC 016 Clause 6.2.3 Type: AppContext.
		err = errors.New("Missing AssociateDevAppId")
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	if len(appContext.AppInfo.UserAppInstanceInfo) == 0 { // ETSI GS MEC 016 Clause 6.2.3 Type: AppContext.
		err = errors.New("Missing at least one UserAppInstanceInfo item")
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	for _, item := range appContext.AppInfo.UserAppInstanceInfo {
		if item.AppInstanceId != "" {
			err = errors.New("UserAppInstanceInfo.AppInstanceId shall not be set")
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		if item.ReferenceURI != "" {
			err = errors.New("UserAppInstanceInfo.ReferenceURI shall not be set")
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
	} // End of 'for' statement

	// Create the AppContext
	var appContextSbi meepdaimgr.AppContext
	appContextSbi.AppAutoInstantiation = appContext.AppAutoInstantiation
@@ -996,3 +1032,21 @@ func errHandlerProblemDetails(w http.ResponseWriter, error string, code int) {
	w.WriteHeader(code)
	fmt.Fprint(w, jsonResponse)
}

func validateQueryParams(params url.Values, validParams []string) error {
	for param := range params {
		found := false
		for _, validParam := range validParams {
			if param == validParam {
				found = true
				break
			}
		}
		if !found {
			err := errors.New("Invalid query param: " + param)
			log.Error(err.Error())
			return err
		}
	}
	return nil
}
+0 −17
Original line number Diff line number Diff line
@@ -1035,23 +1035,6 @@ func (am *DaiMgr) CreateAppContext(appContext *AppContext, remoteUrl string, san
		return nil, errors.New("CreateAppContext: Invalid input parameters")
	}
	app = appContext
	if app.ContextId != "" { // ETSI GS MEC 016 Clause 6.2.3 Type: AppContext.
		return nil, errors.New("ContextId shall not be set")
	}
	if app.AssociateDevAppId == "" { // ETSI GS MEC 016 Clause 6.2.3 Type: AppContext.
		return nil, errors.New("Missing AssociateDevAppId")
	}
	if len(app.AppInfo.UserAppInstanceInfo) == 0 { // ETSI GS MEC 016 Clause 6.2.3 Type: AppContext.
		return nil, errors.New("Missing at least one UserAppInstanceInfo item")
	}
	for _, item := range app.AppInfo.UserAppInstanceInfo {
		if item.AppInstanceId != "" {
			return nil, errors.New("UserAppInstanceInfo.AppInstanceId shall not be set")
		}
		if item.ReferenceURI != "" {
			return nil, errors.New("UserAppInstanceInfo.ReferenceURI shall not be set")
		}
	} // End of 'for' statement

	// Whe creating the context, instantiate the application
	// Retrieve the MEC application description