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
|
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_probesets_returns_probesets() {
if !common::db_available() {
eprintln!(
"skipping dataset_probesets_returns_probesets: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_probesets_returns_probesets: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
if !common::auth_server_available() {
eprintln!("skipping dataset_probesets_returns_probesets: no gn-auth reachable");
return;
}
let response = common::get_with_token(
"GET /datasets/Br_U_0803_M/probesets",
"/datasets/Br_U_0803_M/probesets",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let probesets: Vec<Value> = common::data(&body);
assert!(!probesets.is_empty());
let names: Vec<&str> = probesets
.iter()
.map(|record| record["name"].as_str().unwrap())
.collect();
assert!(names.contains(&"100001_at"));
}
#[tokio::test]
async fn dataset_probesets_without_a_token_returns_401() {
if !common::db_available() {
eprintln!(
"skipping dataset_probesets_without_a_token_returns_401: no usable database (check SQL_URI credentials)"
);
return;
}
let response = common::get(
"GET /datasets/Br_U_0803_M/probesets (no token)",
"/datasets/Br_U_0803_M/probesets",
)
.await;
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}
#[tokio::test]
async fn dataset_probesets_unknown_dataset_returns_404() {
if !common::db_available() {
eprintln!(
"skipping dataset_probesets_unknown_dataset_returns_404: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_probesets_unknown_dataset_returns_404: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
if !common::auth_server_available() {
eprintln!("skipping dataset_probesets_unknown_dataset_returns_404: no gn-auth reachable");
return;
}
let response = common::get_with_token(
"GET /datasets/not-a-real-dataset/probesets",
"/datasets/not-a-real-dataset/probesets",
&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_probesets");
}
/// UTHSC_BXD_Cochlea_0225 (public=1, confidentiality=1, created
/// 2025-02-13) is neither publicly readable by the flags 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 whole listing must be denied rather than silently
/// returned.
#[tokio::test]
async fn dataset_probesets_non_public_unlinked_dataset_returns_403() {
if !common::db_available() {
eprintln!(
"skipping dataset_probesets_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_probesets_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_probesets_non_public_unlinked_dataset_returns_403: no gn-auth reachable"
);
return;
}
let response = common::get_with_token(
"GET /datasets/UTHSC_BXD_Cochlea_0225/probesets",
"/datasets/UTHSC_BXD_Cochlea_0225/probesets",
&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_probesets_recent_non_public_dataset_returns_403() {
if !common::db_available() {
eprintln!(
"skipping dataset_probesets_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_probesets_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_probesets_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",
"/datasets/UTHSC_BXD_2wk_Cochlea_0926/probesets",
&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");
}
|