Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(rules): add test case for maximum rule name length #666

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/main/resources/db/migration/V4.0.0__cryostat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
maxAge bigint not null,
maxSize bigint not null,
metadata jsonb,
name varchar(255),
name text check (char_length(name) < 64),
remoteId bigint not null,
startTime bigint not null,
state smallint check (state between 0 and 4),
Expand All @@ -40,48 +40,48 @@
create table DiscoveryNode (
id bigint not null,
labels jsonb,
name varchar(255) not null,
nodeType varchar(255) not null,
name text not null check (char_length(name) < 255),
nodeType text not null check (char_length(nodeType) < 255),
parentNode bigint,
primary key (id)
);

create table DiscoveryPlugin (
id uuid not null,
builtin boolean not null,
callback varchar(255) unique,
callback text unique,
credential_id bigint unique,
realm_id bigint not null unique,
primary key (id)
);

create table MatchExpression (
id bigint not null,
script varchar(255) not null,
script text not null check (char_length(script) < 1024),
primary key (id)
);

create table Rule (
id bigint not null,
archivalPeriodSeconds integer not null,
description varchar(255),
description text check (char_length(description) < 1024),
enabled boolean not null,
eventSpecifier varchar(255) not null,
eventSpecifier text not null check (char_length(eventSpecifier) < 255),
initialDelaySeconds integer not null,
maxAgeSeconds integer not null,
maxSizeBytes integer not null,
name varchar(255) unique,
name text unique check (char_length(name) < 255),
preservedArchives integer not null,
matchExpression bigint unique,
primary key (id)
);

create table Target (
id bigint not null,
alias varchar(255),
alias text check (char_length(alias) < 255),
annotations jsonb,
connectUrl bytea unique,
jvmId varchar(255),
jvmId text check (char_length(jvmId) < 255),
labels jsonb,
discoveryNode bigint unique,
primary key (id)
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/io/cryostat/rules/RulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.*;

import java.util.Arrays;

import io.cryostat.AbstractTransactionalTestBase;

import io.quarkus.test.common.http.TestHTTPEndpoint;
Expand All @@ -30,6 +32,8 @@
import jakarta.transaction.Transactional;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mockito;

@QuarkusTest
Expand Down Expand Up @@ -244,6 +248,20 @@ public void testCreateThrowsWhenBodyNull() {
.statusCode(400);
}

@ParameterizedTest
@ValueSource(ints = {1, 16, 64, 128, 256})
public void testCreateThrowsWhenNameTooLong(int len) {
char[] c = new char[len];
Arrays.fill(c, 'a');
rule.put("name", new String(c));
final int limit = 255;
given().body(rule.toString())
.contentType(ContentType.JSON)
.post()
.then()
.statusCode(len <= limit ? 201 : 400);
}

@Test
public void testCreateThrowsWhenMandatoryFieldsUnspecified() {
var badRule = new JsonObject();
Expand Down
Loading