|
|
|
@@ -0,0 +1,628 @@
|
|
|
|
|
package com.linkerbot.vibemake.api;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.*;
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.linkerbot.vibemake.bean.PcbContracts.PcbSaveResult;
|
|
|
|
|
import com.linkerbot.vibemake.bean.entity.User;
|
|
|
|
|
import com.linkerbot.vibemake.common.BusinessException;
|
|
|
|
|
import com.linkerbot.vibemake.security.TokenService;
|
|
|
|
|
import com.linkerbot.vibemake.service.UserService;
|
|
|
|
|
import com.linkerbot.vibemake.service.pcb.PcbObjectStore;
|
|
|
|
|
import com.linkerbot.vibemake.service.pcb.PcbProjectService;
|
|
|
|
|
import com.linkerbot.vibemake.service.config.PcbProperties;
|
|
|
|
|
import com.linkerbot.vibemake.service.config.LimitProperties;
|
|
|
|
|
import com.linkerbot.vibemake.service.config.OssProperties;
|
|
|
|
|
import com.linkerbot.vibemake.service.oss.OssPostSigner;
|
|
|
|
|
import com.linkerbot.vibemake.service.oss.OssResourcePaths;
|
|
|
|
|
import com.linkerbot.vibemake.service.support.ProjectSupport;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
import org.junit.jupiter.params.provider.ValueSource;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.*;
|
|
|
|
|
import org.springframework.boot.test.context.*;
|
|
|
|
|
import org.springframework.context.annotation.*;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
|
|
import org.springframework.test.web.servlet.*;
|
|
|
|
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
|
|
|
|
|
|
|
|
|
@SpringBootTest(properties = {
|
|
|
|
|
"spring.datasource.url=jdbc:h2:mem:pcb;MODE=MySQL;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000",
|
|
|
|
|
"spring.datasource.username=sa", "spring.datasource.password=",
|
|
|
|
|
"spring.datasource.driver-class-name=org.h2.Driver",
|
|
|
|
|
"vibemake.repository-write.worker-enabled=false", "vibemake.oss.enabled=false",
|
|
|
|
|
"vibemake.pcb.oss.enabled=true", "vibemake.oss.bucket=shared-oss-tests",
|
|
|
|
|
"vibemake.oss.access-key-id=TestPcbKey", "vibemake.oss.access-key-secret=test-secret",
|
|
|
|
|
"vibemake.oss.public-base-url=https://pcb-cdn.example.com/resources",
|
|
|
|
|
"vibemake.ai.enabled=false", "vibemake.git.enabled=false", "vibemake.limits.enabled=false",
|
|
|
|
|
"logging.level.org.springframework=WARN"
|
|
|
|
|
})
|
|
|
|
|
@ActiveProfiles("test")
|
|
|
|
|
@AutoConfigureMockMvc(print = MockMvcPrint.NONE)
|
|
|
|
|
@Import(PcbWorkspaceTest.Config.class)
|
|
|
|
|
class PcbWorkspaceTest {
|
|
|
|
|
private static final String BASE = "/api/pcb/workspace/projects";
|
|
|
|
|
|
|
|
|
|
@TestConfiguration
|
|
|
|
|
static class Config {
|
|
|
|
|
@Bean @Primary
|
|
|
|
|
FakePcbStore fakePcb(PcbProperties properties, OssProperties oss, ObjectMapper json) {
|
|
|
|
|
return new FakePcbStore(properties, oss, json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class FakePcbStore implements PcbObjectStore {
|
|
|
|
|
final Map<String, byte[]> objects = new ConcurrentHashMap<>();
|
|
|
|
|
final PcbProperties properties;
|
|
|
|
|
final OssProperties oss;
|
|
|
|
|
final OssPostSigner signer;
|
|
|
|
|
boolean unavailable;
|
|
|
|
|
Runnable afterSign;
|
|
|
|
|
Runnable afterSize;
|
|
|
|
|
CyclicBarrier sizeBarrier;
|
|
|
|
|
|
|
|
|
|
FakePcbStore(PcbProperties properties, OssProperties oss, ObjectMapper json) {
|
|
|
|
|
this.properties = properties;
|
|
|
|
|
this.oss = oss;
|
|
|
|
|
this.signer = new OssPostSigner(oss, json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void available() {
|
|
|
|
|
if (!properties.getOss().isEnabled()) throw new BusinessException(503, "PCB_STORAGE_UNAVAILABLE", "关闭");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SignedUpload signUpload(String key, String name, long size, Duration validity) {
|
|
|
|
|
available();
|
|
|
|
|
OssPostSigner.SignedPost post = signer.signObject(key, "application/zip", size, validity, null);
|
|
|
|
|
if (afterSign != null) {
|
|
|
|
|
Runnable action = afterSign;
|
|
|
|
|
afterSign = null;
|
|
|
|
|
action.run();
|
|
|
|
|
}
|
|
|
|
|
return new SignedUpload(oss.uploadUrl(), post.formFields(), post.expiresAt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long size(String key) {
|
|
|
|
|
available();
|
|
|
|
|
if (unavailable) throw new BusinessException(502, "PCB_OSS_ERROR", "不可用");
|
|
|
|
|
byte[] bytes = objects.get(key);
|
|
|
|
|
if (bytes == null) throw new BusinessException(409, "PCB_FILE_MISSING", "缺文件");
|
|
|
|
|
if (sizeBarrier != null) {
|
|
|
|
|
try {
|
|
|
|
|
sizeBarrier.await(5, TimeUnit.SECONDS);
|
|
|
|
|
} catch (Exception error) {
|
|
|
|
|
throw new IllegalStateException(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (afterSize != null) {
|
|
|
|
|
Runnable action = afterSize;
|
|
|
|
|
afterSize = null;
|
|
|
|
|
action.run();
|
|
|
|
|
}
|
|
|
|
|
return bytes.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String documentUrl(String key) {
|
|
|
|
|
available();
|
|
|
|
|
return new OssResourcePaths(oss).publicUrl(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Autowired MockMvc mvc;
|
|
|
|
|
@Autowired ObjectMapper json;
|
|
|
|
|
@Autowired JdbcTemplate jdbc;
|
|
|
|
|
@Autowired UserService users;
|
|
|
|
|
@Autowired TokenService tokens;
|
|
|
|
|
@Autowired PcbProperties properties;
|
|
|
|
|
@Autowired LimitProperties limitProperties;
|
|
|
|
|
@Autowired OssProperties oss;
|
|
|
|
|
@Autowired PcbProjectService service;
|
|
|
|
|
@Autowired FakePcbStore store;
|
|
|
|
|
private String token;
|
|
|
|
|
private long userId;
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
|
void reset() throws Exception {
|
|
|
|
|
SchemaSupport.reset(jdbc);
|
|
|
|
|
properties.getOss().setEnabled(true);
|
|
|
|
|
properties.setMaxFileBytes(268435456);
|
|
|
|
|
properties.setUploadValidity(Duration.ofMinutes(15));
|
|
|
|
|
store.objects.clear();
|
|
|
|
|
store.unavailable = false;
|
|
|
|
|
store.afterSign = null;
|
|
|
|
|
store.afterSize = null;
|
|
|
|
|
store.sizeBarrier = null;
|
|
|
|
|
User user = users.login("pcb-owner@example.invalid");
|
|
|
|
|
userId = user.getId();
|
|
|
|
|
token = tokens.issue(user.getId(), user.getSessionVersion());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MockHttpServletRequestBuilder auth(MockHttpServletRequestBuilder request) {
|
|
|
|
|
return request.header("Authorization", "Bearer " + token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JsonNode perform(MockHttpServletRequestBuilder request, int status) throws Exception {
|
|
|
|
|
MvcResult result = mvc.perform(request).andExpect(status().is(status)).andReturn();
|
|
|
|
|
return json.readTree(result.getResponse().getContentAsString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MockHttpServletRequestBuilder body(MockHttpServletRequestBuilder request, Object body) throws Exception {
|
|
|
|
|
return request.contentType(MediaType.APPLICATION_JSON).content(json.writeValueAsBytes(body));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String create(String name) throws Exception {
|
|
|
|
|
JsonNode project = perform(body(auth(post(BASE)), Map.of("name", name)), 200).path("data");
|
|
|
|
|
assertThat(project.has("id")).isFalse();
|
|
|
|
|
assertThat(project.has("ownerUserId")).isFalse();
|
|
|
|
|
assertThat(project.path("hasDocument").asBoolean()).isFalse();
|
|
|
|
|
assertThat(project.path("version").asLong()).isZero();
|
|
|
|
|
assertThat(project.path("pcbProjectCode").asText()).matches("[0-9a-z]{12}");
|
|
|
|
|
return project.path("pcbProjectCode").asText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JsonNode sign(String code, long version, long size) throws Exception {
|
|
|
|
|
return perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "控制板.zip", "sizeBytes", size, "expectedVersion", version)), 200).path("data");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JsonNode upload(String code, long version, byte[] bytes) throws Exception {
|
|
|
|
|
JsonNode signature = sign(code, version, bytes.length);
|
|
|
|
|
store.objects.put(signature.path("formFields").path("key").asText(), bytes.clone());
|
|
|
|
|
return signature;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JsonNode confirm(String code, JsonNode signature, int status) throws Exception {
|
|
|
|
|
return perform(body(auth(put(BASE + "/" + code + "/document")),
|
|
|
|
|
Map.of("uploadCode", signature.path("uploadCode").asText())), status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void sharedLoginSeparateWorkspaceAndZipReferencesRoundTrip() throws Exception {
|
|
|
|
|
perform(auth(get("/api/users/me")), 200);
|
|
|
|
|
String code = create(" PCB 控制板 ");
|
|
|
|
|
assertThat(perform(auth(get(BASE)), 200).path("data").path("total").asInt()).isEqualTo(1);
|
|
|
|
|
assertThat(perform(auth(get("/api/workspace/projects")), 200).path("data").path("total").asInt()).isZero();
|
|
|
|
|
assertThat(perform(auth(get("/api/cad/workspace/projects")), 200).path("data").path("total").asInt()).isZero();
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM project", Long.class)).isZero();
|
|
|
|
|
assertThat(perform(auth(get(BASE + "/" + code + "/document")), 404).path("code").asText()).isEqualTo("PCB_DOCUMENT_NOT_FOUND");
|
|
|
|
|
|
|
|
|
|
Map<String, byte[]> files = new HashMap<>(Map.of(
|
|
|
|
|
"控制板/控制板.kicad_pro", "{}".getBytes(StandardCharsets.UTF_8),
|
|
|
|
|
"控制板/控制板.kicad_sch", "(kicad_sch)".getBytes(StandardCharsets.UTF_8),
|
|
|
|
|
"控制板/控制板.kicad_pcb", "(kicad_pcb)".getBytes(StandardCharsets.UTF_8),
|
|
|
|
|
"控制板/私有.pretty/接口.kicad_mod", "(footprint)".getBytes(StandardCharsets.UTF_8),
|
|
|
|
|
"控制板/models/model.step", new byte[] {0, 1, 2, -1}));
|
|
|
|
|
byte[] firstBytes = zip(files);
|
|
|
|
|
JsonNode first = upload(code, 0, firstBytes);
|
|
|
|
|
assertThat(first.path("uploadUrl").asText()).isEqualTo(oss.uploadUrl());
|
|
|
|
|
assertThat(first.path("formFields").path("key").asText())
|
|
|
|
|
.startsWith(oss.getRootDirectory() + "/pcb-projects/" + code + "/");
|
|
|
|
|
assertThat(first.path("formFields").path("x-oss-credential").asText())
|
|
|
|
|
.startsWith(oss.getAccessKeyId() + "/");
|
|
|
|
|
assertThat(first.path("formFields").has("x-oss-object-acl")).isFalse();
|
|
|
|
|
assertThat(first.path("formFields").path("content-type").asText()).isEqualTo("application/zip");
|
|
|
|
|
assertThat(confirm(code, first, 200).path("data").path("version").asLong()).isEqualTo(1);
|
|
|
|
|
JsonNode opened = perform(auth(get(BASE + "/" + code + "/document")), 200).path("data");
|
|
|
|
|
assertThat(opened.path("version").asLong()).isEqualTo(1);
|
|
|
|
|
assertThat(opened.path("downloadUrl").asText())
|
|
|
|
|
.isEqualTo(oss.publicBaseUrl() + "/" + first.path("formFields").path("key").asText());
|
|
|
|
|
assertThat(opened.has("expiresAt")).isTrue();
|
|
|
|
|
assertThat(opened.path("expiresAt").isNull()).isTrue();
|
|
|
|
|
assertThat(store.objects.get(first.path("formFields").path("key").asText())).isEqualTo(firstBytes);
|
|
|
|
|
|
|
|
|
|
files.put("控制板/控制板.kicad_pcb", "(kicad_pcb (net 1 GND))".getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
byte[] secondBytes = zip(files);
|
|
|
|
|
JsonNode second = upload(code, opened.path("version").asLong(), secondBytes);
|
|
|
|
|
JsonNode saved = confirm(code, second, 200).path("data");
|
|
|
|
|
assertThat(saved.path("version").asLong()).isEqualTo(2);
|
|
|
|
|
JsonNode detail = perform(auth(get(BASE + "/" + code)), 200).path("data");
|
|
|
|
|
assertThat(detail.path("hasDocument").asBoolean()).isTrue();
|
|
|
|
|
assertThat(detail.path("fileName").asText()).isEqualTo("控制板.zip");
|
|
|
|
|
assertThat(detail.path("sizeBytes").asLong()).isEqualTo(secondBytes.length);
|
|
|
|
|
assertThat(detail.path("savedAt").asText()).doesNotEndWith("Z");
|
|
|
|
|
assertThat(detail.has("documentObjectKey")).isFalse();
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT document_object_key FROM pcb_project WHERE pcb_project_code=?",
|
|
|
|
|
String.class, code)).isEqualTo("/pcb-projects/" + code + "/" + second.path("uploadCode").asText() + "/project.zip");
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT object_key FROM pcb_project_upload WHERE upload_code=?", String.class,
|
|
|
|
|
second.path("uploadCode").asText())).isEqualTo("/pcb-projects/" + code + "/" + second.path("uploadCode").asText() + "/project.zip");
|
|
|
|
|
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + code)), Map.of("name", "重命名", "description", "电机控制板")), 200);
|
|
|
|
|
assertThat(perform(auth(get(BASE + "?keyword=重命")), 200).path("data").path("total").asInt()).isEqualTo(1);
|
|
|
|
|
assertThat(perform(auth(get(BASE + "/" + code)), 200).path("data").path("version").asLong()).isEqualTo(2);
|
|
|
|
|
assertThat(store.objects).hasSize(2);
|
|
|
|
|
JsonNode current = perform(auth(get(BASE + "/" + code + "/document")), 200).path("data");
|
|
|
|
|
assertThat(current.path("version").asLong()).isEqualTo(2);
|
|
|
|
|
assertThat(current.path("downloadUrl").asText())
|
|
|
|
|
.isEqualTo(oss.publicBaseUrl() + "/" + second.path("formFields").path("key").asText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte[] zip(Map<String, byte[]> files) throws Exception {
|
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
|
try (ZipOutputStream zip = new ZipOutputStream(bytes, StandardCharsets.UTF_8)) {
|
|
|
|
|
for (Map.Entry<String, byte[]> file : files.entrySet()) {
|
|
|
|
|
zip.putNextEntry(new ZipEntry(file.getKey()));
|
|
|
|
|
zip.write(file.getValue());
|
|
|
|
|
zip.closeEntry();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bytes.toByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void pcbCoverRoundTripsThroughCreationListingUpdateClearAndDocumentSave() throws Exception {
|
|
|
|
|
String path = "/project-covers/" + "a".repeat(12) + "/20261104/" + "b".repeat(32) + ".png";
|
|
|
|
|
String url = oss.publicBaseUrl() + "/" + oss.getRootDirectory() + path;
|
|
|
|
|
JsonNode created = perform(body(auth(post(BASE)), Map.of("name", "带封面的 PCB", "description", "参数化设计", "coverUrl", url)), 200).path("data");
|
|
|
|
|
String code = created.path("pcbProjectCode").asText();
|
|
|
|
|
assertThat(created.path("coverUrl").asText()).isEqualTo(url);
|
|
|
|
|
assertThat(created.path("version").asLong()).isZero();
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT cover_url FROM pcb_project WHERE pcb_project_code=?", String.class, code)).isEqualTo(path);
|
|
|
|
|
assertThat(perform(auth(get(BASE)), 200).path("data").path("items").get(0).path("coverUrl").asText()).isEqualTo(url);
|
|
|
|
|
assertThat(perform(auth(get(BASE + "/" + code)), 200).path("data").path("coverUrl").asText()).isEqualTo(url);
|
|
|
|
|
|
|
|
|
|
JsonNode receipt = confirm(code, upload(code, 0, new byte[] {80, 75, 3, 4}), 200).path("data");
|
|
|
|
|
String nextPath = path.replace(".png", ".webp");
|
|
|
|
|
String nextUrl = oss.publicBaseUrl() + "/" + oss.getRootDirectory() + nextPath;
|
|
|
|
|
JsonNode changed = perform(body(auth(patch(BASE + "/" + code)), Map.of("coverUrl", nextUrl)), 200).path("data");
|
|
|
|
|
assertThat(changed.path("coverUrl").asText()).isEqualTo(nextUrl);
|
|
|
|
|
assertThat(changed.path("name").asText()).isEqualTo("带封面的 PCB");
|
|
|
|
|
assertThat(changed.path("description").asText()).isEqualTo("参数化设计");
|
|
|
|
|
assertThat(changed.path("version").asLong()).isEqualTo(1);
|
|
|
|
|
assertThat(changed.path("savedAt")).isEqualTo(receipt.path("savedAt"));
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT cover_url FROM pcb_project WHERE pcb_project_code=?", String.class, code)).isEqualTo(nextPath);
|
|
|
|
|
|
|
|
|
|
JsonNode preserved = perform(body(auth(patch(BASE + "/" + code)),
|
|
|
|
|
json.createObjectNode().put("name", "改名").putNull("coverUrl")), 200).path("data");
|
|
|
|
|
assertThat(preserved.path("coverUrl").asText()).isEqualTo(nextUrl);
|
|
|
|
|
confirm(code, upload(code, 1, new byte[] {80, 75, 3, 4, 5}), 200);
|
|
|
|
|
assertThat(perform(auth(get(BASE + "/" + code)), 200).path("data").path("coverUrl").asText()).isEqualTo(nextUrl);
|
|
|
|
|
|
|
|
|
|
String ownerToken = token;
|
|
|
|
|
User other = users.login("pcb-cover-other@example.invalid");
|
|
|
|
|
token = tokens.issue(other.getId(), other.getSessionVersion());
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + code)), Map.of("coverUrl", "")), 404);
|
|
|
|
|
token = ownerToken;
|
|
|
|
|
JsonNode cleared = perform(body(auth(patch(BASE + "/" + code)), Map.of("coverUrl", "")), 200).path("data");
|
|
|
|
|
assertThat(cleared.path("coverUrl").isNull()).isTrue();
|
|
|
|
|
assertThat(cleared.path("version").asLong()).isEqualTo(2);
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT cover_url FROM pcb_project WHERE pcb_project_code=?", String.class, code)).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void optionalAndExternalCoversFollowExistingCoverRules() throws Exception {
|
|
|
|
|
String code = create("无封面");
|
|
|
|
|
assertThat(perform(auth(get(BASE + "/" + code)), 200).path("data").path("coverUrl").isNull()).isTrue();
|
|
|
|
|
String external = "https://images.example.com/pcb.png";
|
|
|
|
|
JsonNode view = perform(body(auth(patch(BASE + "/" + code)), Map.of("coverUrl", external)), 200).path("data");
|
|
|
|
|
assertThat(view.path("coverUrl").asText()).isEqualTo(external);
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT cover_url FROM pcb_project WHERE pcb_project_code=?", String.class, code)).isEqualTo(external);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@ValueSource(strings = {"http://images.example.com/pcb.png", "https://user:password@images.example.com/pcb.png",
|
|
|
|
|
"/project-covers/user/pcb.png", "data:image/png;base64,abcd"})
|
|
|
|
|
void invalidCoverAddressesAreRejectedWithoutChangingProject(String invalid) throws Exception {
|
|
|
|
|
String code = create("封面验证");
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + code)), Map.of("coverUrl", invalid)), 400);
|
|
|
|
|
perform(body(auth(post(BASE)), Map.of("name", "非法封面", "coverUrl", invalid)), 400);
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT cover_url FROM pcb_project WHERE pcb_project_code=?", String.class, code)).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void confirmedBatchReplayReturnsOriginalReceiptEvenAfterLaterSaveExpiryAndOssFailure() throws Exception {
|
|
|
|
|
String code = create("幂等");
|
|
|
|
|
JsonNode first = upload(code, 0, new byte[] {1});
|
|
|
|
|
JsonNode original = confirm(code, first, 200).path("data");
|
|
|
|
|
confirm(code, upload(code, 1, new byte[] {2}), 200);
|
|
|
|
|
jdbc.update("UPDATE pcb_project_upload SET expires_at=?", ProjectSupport.now().minusDays(1));
|
|
|
|
|
store.unavailable = true;
|
|
|
|
|
assertThat(confirm(code, first, 200).path("data")).isEqualTo(original);
|
|
|
|
|
assertThat(service.detail(userId, code).version()).isEqualTo(2);
|
|
|
|
|
JsonNode document = perform(auth(get(BASE + "/" + code + "/document")), 200).path("data");
|
|
|
|
|
assertThat(document.path("version").asLong()).isEqualTo(2);
|
|
|
|
|
assertThat(document.path("downloadUrl").asText()).startsWith(oss.publicBaseUrl() + "/");
|
|
|
|
|
properties.getOss().setEnabled(false);
|
|
|
|
|
assertThat(confirm(code, first, 200).path("data")).isEqualTo(original);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void foreignUsersAndProjectsCannotAccessOrConfirmUploads() throws Exception {
|
|
|
|
|
String code = create("私有设计");
|
|
|
|
|
JsonNode pending = upload(code, 0, new byte[] {1});
|
|
|
|
|
String another = create("另一项目");
|
|
|
|
|
confirm(another, pending, 404);
|
|
|
|
|
User other = users.login("pcb-other@example.invalid");
|
|
|
|
|
token = tokens.issue(other.getId(), other.getSessionVersion());
|
|
|
|
|
assertThat(perform(auth(get(BASE)), 200).path("data").path("total").asInt()).isZero();
|
|
|
|
|
perform(auth(get(BASE + "/" + code)), 404);
|
|
|
|
|
perform(auth(get(BASE + "/" + code + "/document")), 404);
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + code)), Map.of("name", "越权")), 404);
|
|
|
|
|
perform(auth(delete(BASE + "/" + code)), 404);
|
|
|
|
|
perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 1, "expectedVersion", 0)), 404);
|
|
|
|
|
confirm(code, pending, 404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void failuresDoNotReplaceSavedDocumentAndUnconfirmedExpiryIsEnforced() throws Exception {
|
|
|
|
|
String code = create("失败保护");
|
|
|
|
|
confirm(code, upload(code, 0, new byte[] {1}), 200);
|
|
|
|
|
JsonNode next = sign(code, 1, 2);
|
|
|
|
|
assertThat(confirm(code, next, 409).path("code").asText()).isEqualTo("PCB_FILE_MISSING");
|
|
|
|
|
String key = next.path("formFields").path("key").asText();
|
|
|
|
|
store.objects.put(key, new byte[] {2});
|
|
|
|
|
assertThat(confirm(code, next, 409).path("code").asText()).isEqualTo("PCB_FILE_SIZE_MISMATCH");
|
|
|
|
|
store.objects.put(key, new byte[] {2, 3});
|
|
|
|
|
store.unavailable = true;
|
|
|
|
|
assertThat(confirm(code, next, 502).path("code").asText()).isEqualTo("PCB_OSS_ERROR");
|
|
|
|
|
store.unavailable = false;
|
|
|
|
|
jdbc.update("UPDATE pcb_project_upload SET expires_at=? WHERE upload_code=?",
|
|
|
|
|
ProjectSupport.now().minusSeconds(1), next.path("uploadCode").asText());
|
|
|
|
|
assertThat(confirm(code, next, 409).path("code").asText()).isEqualTo("PCB_UPLOAD_EXPIRED");
|
|
|
|
|
assertThat(service.detail(userId, code).version()).isEqualTo(1);
|
|
|
|
|
assertThat(service.detail(userId, code).sizeBytes()).isEqualTo(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void concurrentDifferentBatchesOnlyOneSaveWins() throws Exception {
|
|
|
|
|
String code = create("并发");
|
|
|
|
|
JsonNode first = upload(code, 0, new byte[] {1});
|
|
|
|
|
JsonNode second = upload(code, 0, new byte[] {2});
|
|
|
|
|
store.sizeBarrier = new CyclicBarrier(2);
|
|
|
|
|
try (ExecutorService executor = Executors.newFixedThreadPool(2)) {
|
|
|
|
|
Future<String> one = executor.submit(() -> confirmationOutcome(code, first));
|
|
|
|
|
Future<String> two = executor.submit(() -> confirmationOutcome(code, second));
|
|
|
|
|
assertThat(List.of(one.get(10, TimeUnit.SECONDS), two.get(10, TimeUnit.SECONDS)))
|
|
|
|
|
.containsExactlyInAnyOrder("saved:1", "PCB_VERSION_CONFLICT");
|
|
|
|
|
}
|
|
|
|
|
assertThat(service.detail(userId, code).version()).isEqualTo(1);
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM pcb_project_upload WHERE saved_version IS NOT NULL", Long.class)).isEqualTo(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void concurrentSameBatchOnlyIncrementsOnce() throws Exception {
|
|
|
|
|
String code = create("重复并发");
|
|
|
|
|
JsonNode batch = upload(code, 0, new byte[] {1});
|
|
|
|
|
store.sizeBarrier = new CyclicBarrier(2);
|
|
|
|
|
try (ExecutorService executor = Executors.newFixedThreadPool(2)) {
|
|
|
|
|
Future<PcbSaveResult> one = executor.submit(() -> service.confirm(userId, code, batch.path("uploadCode").asText()));
|
|
|
|
|
Future<PcbSaveResult> two = executor.submit(() -> service.confirm(userId, code, batch.path("uploadCode").asText()));
|
|
|
|
|
assertThat(one.get(10, TimeUnit.SECONDS)).isEqualTo(two.get(10, TimeUnit.SECONDS));
|
|
|
|
|
}
|
|
|
|
|
assertThat(service.detail(userId, code).version()).isEqualTo(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String confirmationOutcome(String code, JsonNode batch) {
|
|
|
|
|
try {
|
|
|
|
|
return "saved:" + service.confirm(userId, code, batch.path("uploadCode").asText()).version();
|
|
|
|
|
} catch (BusinessException error) {
|
|
|
|
|
return error.code();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void failedReceiptWriteRollsBackDocumentAndAllowsRetry() throws Exception {
|
|
|
|
|
String code = create("事务回滚");
|
|
|
|
|
JsonNode batch = upload(code, 0, new byte[] {1});
|
|
|
|
|
jdbc.execute("ALTER TABLE pcb_project_upload ADD CONSTRAINT reject_saved CHECK (saved_version IS NULL)");
|
|
|
|
|
assertThatThrownBy(() -> service.confirm(userId, code, batch.path("uploadCode").asText())).isInstanceOf(RuntimeException.class);
|
|
|
|
|
assertThat(service.detail(userId, code).version()).isZero();
|
|
|
|
|
assertThat(service.detail(userId, code).hasDocument()).isFalse();
|
|
|
|
|
jdbc.execute("ALTER TABLE pcb_project_upload DROP CONSTRAINT reject_saved");
|
|
|
|
|
assertThat(confirm(code, batch, 200).path("data").path("version").asLong()).isEqualTo(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void deletionDuringHeadAndLaterReplayCannotRestoreProject() throws Exception {
|
|
|
|
|
String code = create("删除竞争");
|
|
|
|
|
JsonNode saved = upload(code, 0, new byte[] {1});
|
|
|
|
|
confirm(code, saved, 200);
|
|
|
|
|
JsonNode pending = upload(code, 1, new byte[] {2});
|
|
|
|
|
store.afterSize = () -> service.delete(userId, code);
|
|
|
|
|
confirm(code, pending, 404);
|
|
|
|
|
confirm(code, saved, 404);
|
|
|
|
|
perform(auth(get(BASE + "/" + code)), 404);
|
|
|
|
|
perform(auth(get(BASE + "/" + code + "/document")), 404);
|
|
|
|
|
perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 1, "expectedVersion", 1)), 404);
|
|
|
|
|
assertThat(perform(auth(get(BASE)), 200).path("data").path("total").asInt()).isZero();
|
|
|
|
|
assertThat(store.objects).hasSize(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void deletionDuringSigningDoesNotCreateOrReturnUploadBatch() throws Exception {
|
|
|
|
|
String code = create("签名删除竞争");
|
|
|
|
|
store.afterSign = () -> service.delete(userId, code);
|
|
|
|
|
perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 1, "expectedVersion", 0)), 404);
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM pcb_project_upload", Long.class)).isZero();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void versionChangeDuringSigningDoesNotReturnStaleCredentials() throws Exception {
|
|
|
|
|
String code = create("签名版本竞争");
|
|
|
|
|
JsonNode first = upload(code, 0, new byte[] {1});
|
|
|
|
|
store.afterSign = () -> service.confirm(userId, code, first.path("uploadCode").asText());
|
|
|
|
|
assertThat(perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 1, "expectedVersion", 0)), 409)
|
|
|
|
|
.path("code").asText()).isEqualTo("PCB_VERSION_CONFLICT");
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM pcb_project_upload", Long.class)).isEqualTo(1);
|
|
|
|
|
assertThat(service.detail(userId, code).version()).isEqualTo(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void expiryDuringHeadStillPreventsDocumentChange() throws Exception {
|
|
|
|
|
String code = create("确认过期竞争");
|
|
|
|
|
JsonNode batch = upload(code, 0, new byte[] {1});
|
|
|
|
|
store.afterSize = () -> jdbc.update("UPDATE pcb_project_upload SET expires_at=? WHERE upload_code=?",
|
|
|
|
|
ProjectSupport.now().minusSeconds(1), batch.path("uploadCode").asText());
|
|
|
|
|
assertThat(confirm(code, batch, 409).path("code").asText()).isEqualTo("PCB_UPLOAD_EXPIRED");
|
|
|
|
|
assertThat(service.detail(userId, code).version()).isZero();
|
|
|
|
|
assertThat(jdbc.queryForObject("SELECT saved_version FROM pcb_project_upload WHERE upload_code=?",
|
|
|
|
|
Long.class, batch.path("uploadCode").asText())).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void independentRateLimitsApplyToEachPcbOperationAndUser() throws Exception {
|
|
|
|
|
boolean wasEnabled = limitProperties.isEnabled();
|
|
|
|
|
Map<String, Integer> original = new HashMap<>(limitProperties.getPerMinute());
|
|
|
|
|
try {
|
|
|
|
|
limitProperties.setEnabled(true);
|
|
|
|
|
for (String group : List.of("pcb-create", "pcb-sign", "pcb-save", "pcb-read"))
|
|
|
|
|
limitProperties.getPerMinute().put(group, 1);
|
|
|
|
|
String code = create("限流");
|
|
|
|
|
assertThat(perform(body(auth(post(BASE)), Map.of("name", "创建超额")), 429)
|
|
|
|
|
.path("code").asText()).isEqualTo("RATE_LIMITED");
|
|
|
|
|
JsonNode batch = upload(code, 0, new byte[] {1});
|
|
|
|
|
mvc.perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 1, "expectedVersion", 0)))
|
|
|
|
|
.andExpect(status().isTooManyRequests()).andExpect(header().exists("Retry-After"));
|
|
|
|
|
confirm(code, batch, 200);
|
|
|
|
|
assertThat(confirm(code, batch, 429).path("code").asText()).isEqualTo("RATE_LIMITED");
|
|
|
|
|
perform(auth(get(BASE + "/" + code + "/document")), 200);
|
|
|
|
|
assertThat(perform(auth(get(BASE + "/" + code + "/document")), 429)
|
|
|
|
|
.path("code").asText()).isEqualTo("RATE_LIMITED");
|
|
|
|
|
perform(body(auth(post("/api/cad/workspace/projects")), Map.of("name", "CAD 额度独立")), 200);
|
|
|
|
|
User other = users.login("pcb-rate-other@example.invalid");
|
|
|
|
|
token = tokens.issue(other.getId(), other.getSessionVersion());
|
|
|
|
|
String another = create("另一账号额度");
|
|
|
|
|
confirm(another, upload(another, 0, new byte[] {2}), 200);
|
|
|
|
|
perform(auth(get(BASE + "/" + another + "/document")), 200);
|
|
|
|
|
} finally {
|
|
|
|
|
limitProperties.setPerMinute(original);
|
|
|
|
|
limitProperties.setEnabled(wasEnabled);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void duplicateNamesStablePaginationAndDeletedFilteringPreserveMetadata() throws Exception {
|
|
|
|
|
String first = create("控制板");
|
|
|
|
|
String second = create("控制板");
|
|
|
|
|
jdbc.update("UPDATE pcb_project SET updated_at=?", ProjectSupport.now().minusDays(1));
|
|
|
|
|
JsonNode page = perform(auth(get(BASE + "?page=1&size=1&keyword=控制")), 200).path("data");
|
|
|
|
|
assertThat(page.path("total").asInt()).isEqualTo(2);
|
|
|
|
|
assertThat(page.path("items").get(0).path("pcbProjectCode").asText()).isEqualTo(second);
|
|
|
|
|
assertThat(perform(auth(get(BASE + "?page=2&size=1&keyword=控制")), 200)
|
|
|
|
|
.path("data").path("items").get(0).path("pcbProjectCode").asText()).isEqualTo(first);
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + first)), Map.of("description", "待清空")), 200);
|
|
|
|
|
JsonNode cleared = perform(body(auth(patch(BASE + "/" + first)), Map.of("description", "")), 200).path("data");
|
|
|
|
|
assertThat(cleared.path("description").asText()).isEmpty();
|
|
|
|
|
assertThat(cleared.path("savedAt").isNull()).isTrue();
|
|
|
|
|
perform(auth(delete(BASE + "/" + second)), 200);
|
|
|
|
|
assertThat(perform(auth(get(BASE)), 200).path("data").path("total").asInt()).isEqualTo(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void staleVersionCannotObtainNewUploadCredentialsAndLogoutRevokesPcbAccess() throws Exception {
|
|
|
|
|
String code = create("登录与版本");
|
|
|
|
|
confirm(code, upload(code, 0, new byte[] {1}), 200);
|
|
|
|
|
assertThat(perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 1, "expectedVersion", 0)), 409)
|
|
|
|
|
.path("code").asText()).isEqualTo("PCB_VERSION_CONFLICT");
|
|
|
|
|
perform(auth(post("/api/auth/logout")), 200);
|
|
|
|
|
perform(auth(get(BASE + "/" + code)), 401);
|
|
|
|
|
perform(auth(get("/api/users/me")), 401);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void validatesMetadataLimitsAndStorageDisabledWithoutBlockingProjectDeletion() throws Exception {
|
|
|
|
|
perform(body(auth(post(BASE)), Map.of("name", " ")), 400);
|
|
|
|
|
String code = create("参数检查");
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + code)), Map.of()), 400);
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + code)), Map.of("name", " ")), 400);
|
|
|
|
|
perform(auth(get(BASE + "?page=0")), 400);
|
|
|
|
|
perform(auth(get(BASE + "?size=101")), 400);
|
|
|
|
|
perform(auth(get(BASE + "?keyword=" + "a".repeat(101))), 400);
|
|
|
|
|
properties.setMaxFileBytes(1);
|
|
|
|
|
assertThat(perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 2, "expectedVersion", 0)), 413).path("code").asText()).isEqualTo("PCB_FILE_TOO_LARGE");
|
|
|
|
|
properties.getOss().setEnabled(false);
|
|
|
|
|
assertThat(perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "test.zip", "sizeBytes", 1, "expectedVersion", 0)), 503).path("code").asText()).isEqualTo("PCB_STORAGE_UNAVAILABLE");
|
|
|
|
|
perform(auth(delete(BASE + "/" + code)), 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@ValueSource(strings = {"../project.zip", "dir/project.zip", "dir\\project.zip", "test.step", ".zip", "test.zip\n", "test\u0000.zip"})
|
|
|
|
|
void rejectsNonZipOrUnsafeFileNames(String fileName) throws Exception {
|
|
|
|
|
String code = create("文件名检查");
|
|
|
|
|
perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", fileName, "sizeBytes", 1, "expectedVersion", 0)), 400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@ValueSource(strings = {"\"1\"", "1.5", "null", "-1", "9223372036854775808"})
|
|
|
|
|
void rejectsCoercedOrInvalidNumericInput(String number) throws Exception {
|
|
|
|
|
String code = create("数字检查");
|
|
|
|
|
for (String input : List.of(
|
|
|
|
|
"{\"fileName\":\"test.zip\",\"sizeBytes\":" + number + ",\"expectedVersion\":0}",
|
|
|
|
|
"{\"fileName\":\"test.zip\",\"sizeBytes\":1,\"expectedVersion\":" + number + "}")) {
|
|
|
|
|
perform(auth(post(BASE + "/" + code + "/uploads/signature")).contentType(MediaType.APPLICATION_JSON).content(input), 400);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void acceptsUppercaseZipButRejectsEmptyAndOversizedMetadata() throws Exception {
|
|
|
|
|
String code = create("边界检查");
|
|
|
|
|
perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "工程.ZIP", "sizeBytes", 1, "expectedVersion", 0)), 200);
|
|
|
|
|
perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "工程.zip", "sizeBytes", 0, "expectedVersion", 0)), 400);
|
|
|
|
|
perform(body(auth(post(BASE)), Map.of("name", "a".repeat(101))), 400);
|
|
|
|
|
perform(body(auth(patch(BASE + "/" + code)), Map.of("description", "a".repeat(2001))), 400);
|
|
|
|
|
perform(body(auth(post(BASE + "/" + code + "/uploads/signature")),
|
|
|
|
|
Map.of("fileName", "a".repeat(252) + ".zip", "sizeBytes", 1, "expectedVersion", 0)), 400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void authenticationCorsNoStoreAndOpenApiExposeAllEightOperations() throws Exception {
|
|
|
|
|
mvc.perform(get(BASE)).andExpect(status().isUnauthorized()).andExpect(header().string("Cache-Control", "no-store"));
|
|
|
|
|
mvc.perform(auth(get(BASE)).header("Origin", "https://dev-vibemake.robotquan.com"))
|
|
|
|
|
.andExpect(status().isOk()).andExpect(header().string("Access-Control-Allow-Origin", "https://dev-vibemake.robotquan.com"))
|
|
|
|
|
.andExpect(header().string("Cache-Control", "no-store"));
|
|
|
|
|
JsonNode spec = perform(get("/v3/api-docs"), 200);
|
|
|
|
|
JsonNode paths = spec.path("paths");
|
|
|
|
|
assertThat(paths.path(BASE).has("get")).isTrue();
|
|
|
|
|
assertThat(paths.path(BASE).has("post")).isTrue();
|
|
|
|
|
assertThat(paths.path(BASE + "/{pcbProjectCode}").has("get")).isTrue();
|
|
|
|
|
assertThat(paths.path(BASE + "/{pcbProjectCode}").has("patch")).isTrue();
|
|
|
|
|
assertThat(paths.path(BASE + "/{pcbProjectCode}").has("delete")).isTrue();
|
|
|
|
|
assertThat(paths.path(BASE + "/{pcbProjectCode}/uploads/signature").has("post")).isTrue();
|
|
|
|
|
assertThat(paths.path(BASE + "/{pcbProjectCode}/document").has("get")).isTrue();
|
|
|
|
|
assertThat(paths.path(BASE + "/{pcbProjectCode}/document").has("put")).isTrue();
|
|
|
|
|
// PCB、CAD 与 Git 项目使用独立 DTO,避免 OpenAPI 模型相互污染。
|
|
|
|
|
JsonNode schemas = spec.path("components").path("schemas");
|
|
|
|
|
assertThat(schemas.path("PcbProjectView").path("properties").has("pcbProjectCode")).isTrue();
|
|
|
|
|
assertThat(schemas.path("PcbProjectView").path("properties").has("coverUrl")).isTrue();
|
|
|
|
|
assertThat(schemas.path("PcbCreateProjectInput").path("properties").has("coverUrl")).isTrue();
|
|
|
|
|
assertThat(schemas.path("PcbUpdateProjectInput").path("properties").has("coverUrl")).isTrue();
|
|
|
|
|
assertThat(schemas.path("PcbProjectView").path("properties").has("projectCode")).isFalse();
|
|
|
|
|
assertThat(schemas.path("PcbProjectView").path("properties").has("cadProjectCode")).isFalse();
|
|
|
|
|
assertThat(schemas.path("CadProjectView").path("properties").has("cadProjectCode")).isTrue();
|
|
|
|
|
for (String name : List.of("PcbProjectView", "PcbUploadSignature", "PcbSaveResult", "PcbDocumentView")) {
|
|
|
|
|
assertThat(schemas.path(name).path("properties").has("id")).isFalse();
|
|
|
|
|
assertThat(schemas.path(name).path("properties").has("ownerUserId")).isFalse();
|
|
|
|
|
assertThat(schemas.path(name).path("properties").has("pcbProjectId")).isFalse();
|
|
|
|
|
}
|
|
|
|
|
assertThat(schemas.path("ProjectView").path("properties").has("projectCode")).isTrue();
|
|
|
|
|
assertThat(schemas.path("ProjectView").path("properties").has("pcbProjectCode")).isFalse();
|
|
|
|
|
}
|
|
|
|
|
}
|