(w http.ResponseWriter, request *submit.Request)
| 97 | } |
| 98 | |
| 99 | func validateSubmitRequest(w http.ResponseWriter, request *submit.Request) { |
| 100 | s := system.NewSystem() |
| 101 | osArchitecture, err := s.GetArchitecture() |
| 102 | if err != nil { |
| 103 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 104 | return |
| 105 | } |
| 106 | cpuArchitecture, err := s.GetCpuArchitecture() |
| 107 | if err != nil { |
| 108 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 109 | return |
| 110 | } |
| 111 | osId, err := s.GetOSId() |
| 112 | if err != nil { |
| 113 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | if request.Version != submit.Version { |
| 118 | http.Error(w, fmt.Sprintf("Expected version %s, got %s", submit.Version, request.Version), http.StatusBadRequest) |
| 119 | return |
| 120 | } |
| 121 | if request.OS.Architecture != osArchitecture { |
| 122 | http.Error(w, fmt.Sprintf("Expected OS architecture %s, got %s", osArchitecture, request.OS.Architecture), http.StatusBadRequest) |
| 123 | return |
| 124 | } |
| 125 | if request.OS.Id != osId { |
| 126 | http.Error(w, fmt.Sprintf("Expected OS id %s, got %s", osId, request.OS.Id), http.StatusBadRequest) |
| 127 | return |
| 128 | } |
| 129 | if request.System.Architecture != cpuArchitecture { |
| 130 | http.Error(w, fmt.Sprintf("Expected CPU architecture %s, got %s", cpuArchitecture, request.System.Architecture), http.StatusBadRequest) |
| 131 | return |
| 132 | } |
| 133 | if !regexp.MustCompile(`^https?://.+$`).MatchString(request.Pacman.Mirror) { |
| 134 | http.Error(w, fmt.Sprintf("Invalid HTTP mirror URL: %s", request.Pacman.Mirror), http.StatusBadRequest) |
| 135 | return |
| 136 | } |
| 137 | if len(request.Pacman.Packages) <= 1 { |
| 138 | http.Error(w, "Expected more than 1 package", http.StatusBadRequest) |
| 139 | return |
| 140 | } |
| 141 | if !slices.Contains(request.Pacman.Packages, "pacman-mirrorlist") { |
| 142 | http.Error(w, "Expected package list to contain pacman-mirrorlist", http.StatusBadRequest) |
| 143 | return |
| 144 | } |
| 145 | |
| 146 | w.WriteHeader(http.StatusNoContent) |
| 147 | } |
no test coverage detected