Skip to content

Commit 246de4e

Browse files
committed
fix(entities): reject state transitions away from DELETED
1 parent 5791dfa commit 246de4e

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

server/src/main/java/org/eclipse/openvsx/entities/ExtensionVersion.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ public State getState() {
335335
}
336336

337337
public void setState(State state) {
338+
if (this.state == State.DELETED && state != State.DELETED) {
339+
throw new IllegalStateException("Cannot transition away from DELETED state");
340+
}
338341
this.active = state == State.ACTIVE;
339342
this.state = state;
340343
this.lastUpdated = TimeUtil.getCurrentUTC();
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/** ******************************************************************************
2+
* Copyright (c) 2026 Eclipse Foundation and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
* ****************************************************************************** */
10+
package org.eclipse.openvsx.entities;
11+
12+
import org.junit.jupiter.api.Test;
13+
14+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
15+
import static org.junit.jupiter.api.Assertions.assertThrows;
16+
17+
class ExtensionVersionTest {
18+
19+
@Test
20+
void setStateRejectsTransitionAwayFromDeleted() {
21+
var version = new ExtensionVersion();
22+
version.setState(ExtensionVersion.State.DELETED);
23+
24+
assertThrows(IllegalStateException.class, () -> version.setState(ExtensionVersion.State.ACTIVE));
25+
assertThrows(IllegalStateException.class, () -> version.setState(ExtensionVersion.State.INACTIVE));
26+
assertThat(version.getState()).isEqualTo(ExtensionVersion.State.DELETED);
27+
assertThat(version.isActive()).isFalse();
28+
}
29+
30+
@Test
31+
void setStateDeletedIsIdempotent() {
32+
var version = new ExtensionVersion();
33+
version.setState(ExtensionVersion.State.DELETED);
34+
35+
version.setState(ExtensionVersion.State.DELETED);
36+
assertThat(version.getState()).isEqualTo(ExtensionVersion.State.DELETED);
37+
}
38+
39+
@Test
40+
void setActiveOnDeletedVersionThrows() {
41+
var version = new ExtensionVersion();
42+
version.setState(ExtensionVersion.State.DELETED);
43+
44+
assertThrows(IllegalStateException.class, () -> version.setActive(false));
45+
assertThrows(IllegalStateException.class, () -> version.setActive(true));
46+
assertThat(version.getState()).isEqualTo(ExtensionVersion.State.DELETED);
47+
assertThat(version.isActive()).isFalse();
48+
}
49+
50+
@Test
51+
void setActiveTransitionsBetweenActiveAndInactive() {
52+
var version = new ExtensionVersion();
53+
54+
version.setActive(false);
55+
assertThat(version.getState()).isEqualTo(ExtensionVersion.State.INACTIVE);
56+
assertThat(version.isActive()).isFalse();
57+
58+
version.setActive(true);
59+
assertThat(version.getState()).isEqualTo(ExtensionVersion.State.ACTIVE);
60+
assertThat(version.isActive()).isTrue();
61+
}
62+
}

0 commit comments

Comments
 (0)