1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
use axum::http::StatusCode;
use http_body_util::BodyExt;
use serde_json::Value;
mod common;
/// Needs a live MariaDB connection (SQL_URI, see src/db.rs) and a live
/// gn-auth (AUTH_SERVER_URL) plus GN4_TEST_AUTH_TOKEN (see
/// docs/gn-auth.md); skips rather than fails when either is missing,
/// same as dataset_probeset_info.rs. Dataset Br_U_0803_M's CreateTime
/// is 2003-08-01, so it's publicly readable regardless of its
/// public/confidentiality flags (see src/auth.rs) -- a valid token is
/// still required, but no gn-auth authorization call happens.
#[tokio::test]
async fn dataset_probeset_values_returns_strain_values() {
if !common::db_available() {
eprintln!(
"skipping dataset_probeset_values_returns_strain_values: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_probeset_values_returns_strain_values: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
if !common::auth_server_available() {
eprintln!("skipping dataset_probeset_values_returns_strain_values: no gn-auth reachable");
return;
}
let response = common::get_with_token(
"GET /datasets/Br_U_0803_M/probesets/100001_at/values",
"/datasets/Br_U_0803_M/probesets/100001_at/values",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let values: Vec<Value> = common::data(&body);
assert!(!values.is_empty());
let bxd1 = values
.iter()
.find(|v| v["name"] == "BXD1")
.expect("BXD1 in /datasets/Br_U_0803_M/probesets/100001_at/values");
assert!(bxd1["value"].as_f64().is_some());
}
#[tokio::test]
async fn dataset_probeset_values_without_a_token_returns_401() {
if !common::db_available() {
eprintln!(
"skipping dataset_probeset_values_without_a_token_returns_401: no usable database (check SQL_URI credentials)"
);
return;
}
let response = common::get(
"GET /datasets/Br_U_0803_M/probesets/100001_at/values (no token)",
"/datasets/Br_U_0803_M/probesets/100001_at/values",
)
.await;
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}
#[tokio::test]
async fn dataset_probeset_values_unknown_dataset_returns_404() {
if !common::db_available() {
eprintln!(
"skipping dataset_probeset_values_unknown_dataset_returns_404: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_probeset_values_unknown_dataset_returns_404: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
if !common::auth_server_available() {
eprintln!(
"skipping dataset_probeset_values_unknown_dataset_returns_404: no gn-auth reachable"
);
return;
}
let response = common::get_with_token(
"GET /datasets/not-a-real-dataset/probesets/100001_at/values",
"/datasets/not-a-real-dataset/probesets/100001_at/values",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::NOT_FOUND);
let body = response.into_body().collect().await.unwrap().to_bytes();
let error: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(error["status"], 404);
assert_eq!(error["code"], "dataset_not_found");
assert_eq!(error["operation_id"], "dataset_probeset_values");
}
#[tokio::test]
async fn dataset_probeset_values_unknown_probeset_in_dataset_returns_404() {
if !common::db_available() {
eprintln!(
"skipping dataset_probeset_values_unknown_probeset_in_dataset_returns_404: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_probeset_values_unknown_probeset_in_dataset_returns_404: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
if !common::auth_server_available() {
eprintln!(
"skipping dataset_probeset_values_unknown_probeset_in_dataset_returns_404: no gn-auth reachable"
);
return;
}
let response = common::get_with_token(
"GET /datasets/Br_U_0803_M/probesets/not-a-real-probeset/values",
"/datasets/Br_U_0803_M/probesets/not-a-real-probeset/values",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::NOT_FOUND);
let body = response.into_body().collect().await.unwrap().to_bytes();
let error: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(error["status"], 404);
assert_eq!(error["code"], "probeset_not_found");
assert_eq!(error["operation_id"], "dataset_probeset_values");
}
/// UTHSC_BXD_Cochlea_0225 (public=1, confidentiality=1, created
/// 2025-02-13) is neither publicly readable by the flags
/// (confidentiality >= 1) nor old enough for the embargo-age rule, and
/// has never been linked to a gn-auth resource -- so even the token's
/// owner has no privilege on it, and the request must be denied rather
/// than silently allowed.
#[tokio::test]
async fn dataset_probeset_values_non_public_unlinked_dataset_returns_403() {
if !common::db_available() {
eprintln!(
"skipping dataset_probeset_values_non_public_unlinked_dataset_returns_403: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_probeset_values_non_public_unlinked_dataset_returns_403: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
if !common::auth_server_available() {
eprintln!(
"skipping dataset_probeset_values_non_public_unlinked_dataset_returns_403: no gn-auth reachable"
);
return;
}
let response = common::get_with_token(
"GET /datasets/UTHSC_BXD_Cochlea_0225/probesets/ENSMUSG00000028180/values",
"/datasets/UTHSC_BXD_Cochlea_0225/probesets/ENSMUSG00000028180/values",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::FORBIDDEN);
let body = response.into_body().collect().await.unwrap().to_bytes();
let error: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(error["code"], "forbidden");
}
/// Same as above, but with a dataset genuinely less than a year old
/// (UTHSC_BXD_Cochlea_0225 above is real but was already ~20 months
/// old by the time this test was written) -- the age-embargo rule and
/// the "not yet linked to any gn-auth resource" deny path both need to
/// hold for freshly-added data, not just for something that merely
/// hasn't aged into public yet. UTHSC_BXD_2wk_Cochlea_0926
/// (public=1, confidentiality=1, created 2026-09-01) is the most
/// recently added ProbeSetFreeze in the database as of this writing.
#[tokio::test]
async fn dataset_probeset_values_recent_non_public_dataset_returns_403() {
if !common::db_available() {
eprintln!(
"skipping dataset_probeset_values_recent_non_public_dataset_returns_403: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_probeset_values_recent_non_public_dataset_returns_403: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
if !common::auth_server_available() {
eprintln!(
"skipping dataset_probeset_values_recent_non_public_dataset_returns_403: no gn-auth reachable"
);
return;
}
let response = common::get_with_token(
"GET /datasets/UTHSC_BXD_2wk_Cochlea_0926/probesets/ENSMUSG00000028180/values",
"/datasets/UTHSC_BXD_2wk_Cochlea_0926/probesets/ENSMUSG00000028180/values",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::FORBIDDEN);
let body = response.into_body().collect().await.unwrap().to_bytes();
let error: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(error["code"], "forbidden");
}
|