Skip to content

Commit

Permalink
Report hosted queue errors regardless of token kind (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Oct 20, 2023
1 parent 5f7fb87 commit e55cc12
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.6.4

ABQ 1.6.4 is a patch release.

Prior to this release, using `abq test` or `abq report` with an RWX organization
access token to connect to a hosted queue that failed to find an appropriate
queue would result in the ABQ invocation falling back to local mode. Now, ABQ
will exit with an error.

## 1.6.3

ABQ 1.6.3 is a patch release.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/abq_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "abq"
version = "1.6.3"
version = "1.6.4"
edition = "2021"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/abq_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ struct QueueLocationConfig {

fn determine_queue_location(config: QueueLocationConfig) -> QueueLocation {
match config.access_token_kind {
Some(AccessTokenKind::Personal) => {
Some(_) => {
match (
config.run_id_provided,
config.usage_error_from_api,
Expand All @@ -680,7 +680,7 @@ fn determine_queue_location(config: QueueLocationConfig) -> QueueLocation {
},
}
}
_ => match config.queue_addr {
None => match config.queue_addr {
Some(queue_addr) => QueueLocation::Remote(queue_addr),
None => QueueLocation::Ephemeral {
opt_tls_key: config.tls_key,
Expand Down
109 changes: 109 additions & 0 deletions crates/abq_cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4650,6 +4650,115 @@ fn test_run_with_pat_and_run_id_that_doesnt_exist() {
term(queue_proc);
}

#[test]
#[with_protocol_version]
#[serial]
fn test_unsupported_queue_with_org_access_token() {
let name = "test_unsupported_queue_with_org_access_token";
let conf = CSConfigOptions {
use_auth_token: true,
tls: true,
};
let (queue_proc, ..) = setup_queue!(name, conf);

let access_token = test_access_token();

{
let mut server = Server::new();
let in_run_id = "test-run-id";
let queue_mock = server
.mock("GET", "/queue")
.match_header("Authorization", format!("Bearer {}", access_token).as_str())
.match_header("User-Agent", format!("abq/{}", abq_utils::VERSION).as_str())
.match_query(Matcher::AnyOf(vec![Matcher::UrlEncoded(
"run_id".to_string(),
in_run_id.to_string(),
)]))
.with_status(200)
.with_header("content-type", "application/json")
.with_body(
json!({
"usage_error": "Your ABQ version is not supported.",
"rwx_access_token_kind": "organization_access_token",
})
.to_string(),
)
.expect(2)
.create();

let test_args = {
let args = vec![
format!("test"),
format!("--worker=1"),
format!("--run-id=test-run-id"),
format!("--access-token={access_token}"),
format!("-n=1"),
];
let mut args = conf.extend_args_for_client(args);
args.extend([s!("--"), s!("false")]);
args
};

let CmdOutput {
exit_status,
stderr,
stdout,
} = Abq::new(format!("{name}_initial"))
.args(test_args)
.always_capture_stderr(true)
.env([("ABQ_API", server.url())])
.run();

assert!(
!exit_status.success(),
"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
);
assert!(
stderr.contains(
"ABQ was unable to find a queue to run against. Your ABQ version is not supported."
),
"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
);

// abq report --reporter dot --queue-addr ... --run-id ... (--token ...)?
let report_args = {
let args = vec![
format!("report"),
format!("--reporter=dot"),
format!("--run-id=test-run-id"),
format!("--access-token={access_token}"),
format!("--color=never"),
];
conf.extend_args_for_client(args)
};

let CmdOutput {
stdout,
stderr,
exit_status,
} = Abq::new(name.to_string() + "_report")
.args(report_args)
.always_capture_stderr(true)
.env([("ABQ_API", server.url())])
.run();

assert!(
!exit_status.success(),
"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
);
assert!(
stderr.contains(
"ABQ was unable to find a queue to run against. Your ABQ version is not supported."
),
"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
);

queue_mock.assert();
}

term(queue_proc);
}

#[test]
#[with_protocol_version]
#[serial]
Expand Down

0 comments on commit e55cc12

Please sign in to comment.