Skip to content
Merged
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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
target/
bench/
docs/
tests/
clients/
*.md
!LICENSE*
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: build
run: cargo build --workspace
- name: test
run: cargo test --workspace

Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crates/ember-persistence",
"crates/ember-cluster",
"crates/ember-cli",
"tests/integration",
]
resolver = "2"

Expand Down
39 changes: 30 additions & 9 deletions crates/ember-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use rustyline::hint::Hinter;
use rustyline::validate::Validator;
use rustyline::{CompletionType, Config, Context, Editor, Helper};

use crate::commands::{command_names, commands_by_group, find_command, has_subcommands, subcommands};
use crate::commands::{
command_names, commands_by_group, find_command, has_subcommands, subcommands,
};
use crate::connection::{Connection, ConnectionError};
use crate::format::format_response;

Expand Down Expand Up @@ -433,9 +435,7 @@ impl Highlighter for EmberHelper {
let rest = &trimmed[first_end..];

let is_known = find_command(first).is_some()
|| LOCAL_COMMANDS
.iter()
.any(|c| c.eq_ignore_ascii_case(first));
|| LOCAL_COMMANDS.iter().any(|c| c.eq_ignore_ascii_case(first));

let highlighted_cmd = if is_known {
format!("\x1b[1;36m{first}\x1b[0m") // bold cyan
Expand Down Expand Up @@ -466,7 +466,12 @@ impl Highlighter for EmberHelper {
Cow::Owned(format!("\x1b[2m{hint}\x1b[0m")) // dim
}

fn highlight_char(&self, _line: &str, _pos: usize, _kind: rustyline::highlight::CmdKind) -> bool {
fn highlight_char(
&self,
_line: &str,
_pos: usize,
_kind: rustyline::highlight::CmdKind,
) -> bool {
true // re-highlight on every keystroke
}
}
Expand Down Expand Up @@ -656,7 +661,11 @@ mod tests {
#[test]
fn hint_shows_args_for_known_command() {
let h = EmberHelper;
let hint = h.hint("SET ", 4, &Context::new(&rustyline::history::DefaultHistory::new()));
let hint = h.hint(
"SET ",
4,
&Context::new(&rustyline::history::DefaultHistory::new()),
);
assert!(hint.is_some());
let hint = hint.unwrap();
assert!(hint.contains("key"));
Expand All @@ -665,7 +674,11 @@ mod tests {
#[test]
fn hint_shows_subcommands_for_cluster() {
let h = EmberHelper;
let hint = h.hint("CLUSTER ", 8, &Context::new(&rustyline::history::DefaultHistory::new()));
let hint = h.hint(
"CLUSTER ",
8,
&Context::new(&rustyline::history::DefaultHistory::new()),
);
assert!(hint.is_some());
let hint = hint.unwrap();
assert!(hint.contains("INFO"));
Expand All @@ -674,14 +687,22 @@ mod tests {
#[test]
fn hint_none_for_unknown_command() {
let h = EmberHelper;
let hint = h.hint("FOOBAR ", 7, &Context::new(&rustyline::history::DefaultHistory::new()));
let hint = h.hint(
"FOOBAR ",
7,
&Context::new(&rustyline::history::DefaultHistory::new()),
);
assert!(hint.is_none());
}

#[test]
fn hint_none_when_cursor_not_at_end() {
let h = EmberHelper;
let hint = h.hint("SET key", 3, &Context::new(&rustyline::history::DefaultHistory::new()));
let hint = h.hint(
"SET key",
3,
&Context::new(&rustyline::history::DefaultHistory::new()),
);
assert!(hint.is_none());
}
}
9 changes: 7 additions & 2 deletions crates/ember-core/src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,14 @@ pub enum ShardRequest {
pattern: Option<String>,
},
/// Counts keys in this shard that hash to the given cluster slot.
CountKeysInSlot { slot: u16 },
CountKeysInSlot {
slot: u16,
},
/// Returns up to `count` keys that hash to the given cluster slot.
GetKeysInSlot { slot: u16, count: usize },
GetKeysInSlot {
slot: u16,
count: usize,
},
}

/// The shard's response to a request.
Expand Down
12 changes: 3 additions & 9 deletions crates/ember-server/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ impl ClusterCoordinator {
{
let state = self.state.read().await;
if !state.owns_slot(slot) {
return Frame::Error(format!(
"ERR I'm not the owner of hash slot {slot}"
));
return Frame::Error(format!("ERR I'm not the owner of hash slot {slot}"));
}
}

Expand Down Expand Up @@ -644,9 +642,7 @@ mod tests {
state.add_node(node);
}

let resp = coord
.cluster_setslot_node(100, &target.0.to_string())
.await;
let resp = coord.cluster_setslot_node(100, &target.0.to_string()).await;
assert!(matches!(resp, Frame::Simple(_)));

// verify the slot is now owned by the target
Expand All @@ -672,9 +668,7 @@ mod tests {
}

// complete with NODE — should clean up migration state
let resp = coord
.cluster_setslot_node(0, &target.0.to_string())
.await;
let resp = coord.cluster_setslot_node(0, &target.0.to_string()).await;
assert!(matches!(resp, Frame::Simple(_)));

// migration should be cleaned up
Expand Down
8 changes: 2 additions & 6 deletions crates/ember-server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,13 +1554,9 @@ async fn execute(
}
}

Command::ClusterReplicate { .. } => {
Frame::Error("ERR REPLICATE not yet supported".into())
}
Command::ClusterReplicate { .. } => Frame::Error("ERR REPLICATE not yet supported".into()),

Command::ClusterFailover { .. } => {
Frame::Error("ERR FAILOVER not yet supported".into())
}
Command::ClusterFailover { .. } => Frame::Error("ERR FAILOVER not yet supported".into()),

Command::Migrate { .. } => Frame::Error("ERR not yet implemented".into()),

Expand Down
17 changes: 17 additions & 0 deletions tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "ember-integration-tests"
version.workspace = true
edition.workspace = true
publish = false
autobins = false

[[test]]
name = "integration"
path = "src/main.rs"
harness = true

[dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "net", "io-util", "time"] }
bytes = { workspace = true }
ember-protocol = { workspace = true }
tempfile = "3"
40 changes: 40 additions & 0 deletions tests/integration/src/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Integration tests for authentication.

use crate::helpers::{ServerOptions, TestServer};

#[tokio::test]
async fn auth_required() {
let server = TestServer::start_with(ServerOptions {
requirepass: Some("secret123".into()),
..Default::default()
});
let mut c = server.connect().await;

// commands should be rejected before AUTH
let msg = c.err(&["SET", "key", "val"]).await;
assert!(msg.contains("NOAUTH"));

// wrong password
let msg = c.err(&["AUTH", "wrongpass"]).await;
assert!(msg.contains("WRONGPASS"));

// correct password
c.ok(&["AUTH", "secret123"]).await;

// commands work after auth
c.ok(&["SET", "key", "val"]).await;
assert_eq!(c.get_bulk(&["GET", "key"]).await, Some("val".into()));
}

#[tokio::test]
async fn ping_allowed_without_auth() {
let server = TestServer::start_with(ServerOptions {
requirepass: Some("pass".into()),
..Default::default()
});
let mut c = server.connect().await;

// PING should work even without auth
let resp = c.cmd(&["PING"]).await;
assert!(matches!(resp, ember_protocol::Frame::Simple(ref s) if s == "PONG"));
}
Loading