Stufe 4c (#764): Bezeichner auf Englisch - Typen, Methoden, Felder, Parameter, Locals, Testnamen
Mit Roslyn umbenannt (Verweise folgen, Zeichenketten bleiben unberuehrt). Nicht umbenannt, weil gespeichert oder ueber die API gebunden (Stufe 4e): Properties, Record-Parameter, Enum-Member sowie die Parameter der Endpunkt-Handler (Routen-/Query-Bindung ueber den Namen). Die JSON-Felder anonymer Objekte bleiben ausdruecklich benannt (JsonFilter: pfad). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
837a634a22
commit
77062facc9
+21
-21
@@ -12,18 +12,18 @@ namespace ClawdDotNet.Tools.Tests.Database;
|
||||
/// Pre-check (#579), approval key (#609) and permissions (#641) of the Database tool -
|
||||
/// all checkable without a database connection, because it only looks at configuration and statement.
|
||||
/// </summary>
|
||||
public sealed class DatabaseVorpruefungTests
|
||||
public sealed class DatabasePreCheckTests
|
||||
{
|
||||
private static readonly DatabaseTool Tool = new();
|
||||
|
||||
private static AgentToolContext Kontext(string accessLevel, params string[] tabellen) => new(
|
||||
private static AgentToolContext Context(string accessLevel, params string[] tables) => new(
|
||||
"agent", "inst",
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["type"] = "mysql",
|
||||
["connectionString"] = "Server=nirgends",
|
||||
["accessLevel"] = accessLevel,
|
||||
["allowedTables"] = JsonSerializer.SerializeToElement(tabellen)
|
||||
["allowedTables"] = JsonSerializer.SerializeToElement(tables)
|
||||
},
|
||||
new NullStateStore(), NullLogger.Instance, CancellationToken.None);
|
||||
|
||||
@@ -31,13 +31,13 @@ public sealed class DatabaseVorpruefungTests
|
||||
=> JsonSerializer.SerializeToElement(new { action, sql });
|
||||
|
||||
[Fact]
|
||||
public void Fremde_Tabelle_wird_vorab_abgelehnt()
|
||||
=> Tool.Preflight(Sql("SELECT * FROM protokoll"), Kontext("ReadOnly", "messwerte"))
|
||||
public void Foreign_table_is_rejected_up_front()
|
||||
=> Tool.Preflight(Sql("SELECT * FROM protokoll"), Context("ReadOnly", "messwerte"))
|
||||
.ShouldNotBeNull().ShouldContain("protokoll");
|
||||
|
||||
[Fact]
|
||||
public void Kommentare_werden_vorab_abgelehnt()
|
||||
=> Tool.Preflight(Sql("DELETE FROM messwerte -- messwerte"), Kontext("Admin", "messwerte"))
|
||||
public void Comments_are_rejected_up_front()
|
||||
=> Tool.Preflight(Sql("DELETE FROM messwerte -- messwerte"), Context("Admin", "messwerte"))
|
||||
.ShouldNotBeNull();
|
||||
|
||||
[Theory]
|
||||
@@ -46,11 +46,11 @@ public sealed class DatabaseVorpruefungTests
|
||||
[InlineData("ALTER TABLE messwerte ADD COLUMN x INT", "ReadWrite")]
|
||||
[InlineData("CREATE TABLE IF NOT EXISTS messwerte (id INT)", "Admin")]
|
||||
[InlineData("DESCRIBE messwerte", "ReadOnly")]
|
||||
public void Die_Vorpruefung_urteilt_nicht_mehr_ueber_die_Operation(string sql, string level)
|
||||
public void The_pre_check_no_longer_judges_the_operation(string sql, string level)
|
||||
{
|
||||
// #641: Whether an INSERT of a reading agent runs, is presented or is forbidden
|
||||
// is decided by the approval point - no longer by a silent refusal in the tool.
|
||||
Tool.Preflight(Sql(sql), Kontext(level, "messwerte")).ShouldBeNull();
|
||||
Tool.Preflight(Sql(sql), Context(level, "messwerte")).ShouldBeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -64,36 +64,36 @@ public sealed class DatabaseVorpruefungTests
|
||||
[InlineData("ALTER TABLE messwerte ADD COLUMN x INT", "query", "alter")]
|
||||
[InlineData("DROP TABLE IF EXISTS messwerte", "query", "drop")]
|
||||
[InlineData("insert into messwerte (ort) values ('select')", "query", "insert")]
|
||||
public void Der_Freigabeschluessel_ist_die_SQL_Operation_nicht_das_action_Argument(string sql, string action, string erwartet)
|
||||
=> Tool.StagingAktion(Sql(sql, action)).ShouldBe(erwartet);
|
||||
public void The_approval_key_is_the_SQL_operation_not_the_action_argument(string sql, string action, string expected)
|
||||
=> Tool.StagingAction(Sql(sql, action)).ShouldBe(expected);
|
||||
|
||||
[Theory]
|
||||
[InlineData("query", "select")]
|
||||
[InlineData("insert", "insert")]
|
||||
[InlineData("upsert", "update")]
|
||||
public void MongoDB_Aktionen_werden_auf_dieselben_Operationen_abgebildet(string action, string erwartet)
|
||||
=> Tool.StagingAktion(JsonSerializer.SerializeToElement(new { action, collection = "c" })).ShouldBe(erwartet);
|
||||
public void MongoDB_actions_are_mapped_to_the_same_operations(string action, string expected)
|
||||
=> Tool.StagingAction(JsonSerializer.SerializeToElement(new { action, collection = "c" })).ShouldBe(expected);
|
||||
|
||||
[Fact]
|
||||
public void Die_Operationen_sind_fuer_die_Oberflaeche_aufgezaehlt()
|
||||
public void The_operations_are_enumerated_for_the_UI()
|
||||
=> Tool.Operationen.ShouldBe(["select", "insert", "update", "delete", "replace", "create", "alter", "drop", "truncate"]);
|
||||
|
||||
[Theory]
|
||||
[InlineData("select", StagingDecision.Auto)]
|
||||
[InlineData("insert", StagingDecision.Approve)]
|
||||
[InlineData("alter", StagingDecision.Approve)]
|
||||
public void Ohne_erlaubt_liest_der_Agent_frei_und_legt_alles_andere_vor(string operation, StagingDecision erwartet)
|
||||
=> Tool.Vorgabe(operation, new Dictionary<string, object?>()).ShouldBe(erwartet);
|
||||
public void Without_allowed_the_agent_reads_freely_and_submits_everything_else(string operation, StagingDecision expected)
|
||||
=> Tool.Vorgabe(operation, new Dictionary<string, object?>()).ShouldBe(expected);
|
||||
|
||||
[Fact]
|
||||
public async Task Ohne_Freigabestelle_bleibt_die_Zugriffsstufe_eine_harte_Grenze()
|
||||
public async Task Without_an_approver_the_access_tier_stays_a_hard_limit()
|
||||
{
|
||||
// No gate, no check: then the tool itself has to refuse before it
|
||||
// even establishes a connection.
|
||||
var ergebnis = await Tool.ExecuteAsync(
|
||||
Sql("INSERT INTO messwerte (ort) VALUES ('Berlin')"), Kontext("ReadOnly", "messwerte"), default);
|
||||
var result = await Tool.ExecuteAsync(
|
||||
Sql("INSERT INTO messwerte (ort) VALUES ('Berlin')"), Context("ReadOnly", "messwerte"), default);
|
||||
|
||||
ergebnis.Success.ShouldBeFalse();
|
||||
ergebnis.ErrorMessage.ShouldNotBeNull().ShouldContain("ReadOnly");
|
||||
result.Success.ShouldBeFalse();
|
||||
result.ErrorMessage.ShouldNotBeNull().ShouldContain("ReadOnly");
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public sealed class SchemaLookupTests : IDisposable
|
||||
[Fact]
|
||||
public void Describe_is_a_read_and_is_checked_before_approval()
|
||||
{
|
||||
_tool.StagingAktion(JsonSerializer.SerializeToElement(new { action = "describe", table = "messwerte" })).ShouldBe("select");
|
||||
_tool.StagingAction(JsonSerializer.SerializeToElement(new { action = "describe", table = "messwerte" })).ShouldBe("select");
|
||||
_tool.Preflight(JsonSerializer.SerializeToElement(new { action = "describe", table = "geheim" }), Context("messwerte"))
|
||||
.ShouldNotBeNull();
|
||||
_tool.Preflight(JsonSerializer.SerializeToElement(new { action = "describe", table = "messwerte" }), Context("messwerte"))
|
||||
|
||||
@@ -30,7 +30,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("DESCRIBE prices", SqlOperation.Read)]
|
||||
[InlineData("DESC prices", SqlOperation.Read)]
|
||||
[InlineData("SHOW COLUMNS FROM prices", SqlOperation.Read)]
|
||||
public void IF_NOT_EXISTS_und_Strukturabfragen_nennen_die_richtige_Tabelle(string sql, SqlOperation operation)
|
||||
public void IF_NOT_EXISTS_and_structure_queries_name_the_right_table(string sql, SqlOperation operation)
|
||||
{
|
||||
var result = Inspect(sql);
|
||||
|
||||
@@ -43,7 +43,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("CREATE TABLE IF NOT EXISTS users (id INT)")]
|
||||
[InlineData("DROP TABLE IF EXISTS users")]
|
||||
[InlineData("DESCRIBE users")]
|
||||
public void IF_EXISTS_und_DESCRIBE_oeffnen_keine_fremde_Tabelle(string sql)
|
||||
public void IF_EXISTS_and_DESCRIBE_open_no_foreign_table(string sql)
|
||||
=> Inspect(sql).IsValid.ShouldBeFalse();
|
||||
|
||||
[Theory]
|
||||
@@ -52,7 +52,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("DROP TABLE users -- prices")]
|
||||
[InlineData("UPDATE users SET admin=1 -- prices")]
|
||||
[InlineData("SELECT * FROM users # prices")]
|
||||
public void Kommentare_koennen_keine_erlaubte_Tabelle_vortaeuschen(string sql)
|
||||
public void Comments_cannot_fake_an_allowed_table(string sql)
|
||||
{
|
||||
var result = Inspect(sql);
|
||||
|
||||
@@ -63,7 +63,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("SELECT * FROM users WHERE note = 'prices'")]
|
||||
[InlineData("INSERT INTO users (name) VALUES ('prices')")]
|
||||
[InlineData("SELECT * FROM users WHERE a = \"prices\"")]
|
||||
public void String_Literale_koennen_keine_erlaubte_Tabelle_vortaeuschen(string sql)
|
||||
public void String_literals_cannot_fake_an_allowed_table(string sql)
|
||||
{
|
||||
Inspect(sql).IsValid.ShouldBeFalse();
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("SELECT * FROM prices; DROP TABLE users")]
|
||||
[InlineData("SELECT * FROM prices; DELETE FROM users")]
|
||||
[InlineData("SELECT 1; SELECT 2")]
|
||||
public void Mehrere_Statements_werden_abgelehnt(string sql)
|
||||
public void Multiple_statements_are_rejected(string sql)
|
||||
{
|
||||
var result = Inspect(sql);
|
||||
|
||||
@@ -84,7 +84,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("SELECT * FROM prices JOIN users ON users.id = prices.uid")]
|
||||
[InlineData("SELECT * FROM prices, users")]
|
||||
[InlineData("INSERT INTO users SELECT * FROM prices")]
|
||||
public void Ein_einziger_unerlaubter_Join_reicht_zur_Ablehnung(string sql)
|
||||
public void A_single_disallowed_join_is_enough_for_rejection(string sql)
|
||||
{
|
||||
// Crucial: EVERY referenced table must be allowed, not just any one.
|
||||
var result = Inspect(sql);
|
||||
@@ -94,7 +94,7 @@ public sealed class SqlGuardTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ohne_Whitelist_wird_nichts_durchgelassen()
|
||||
public void Without_whitelist_nothing_is_let_through()
|
||||
{
|
||||
SqlGuard.Inspect("SELECT * FROM prices", []).IsValid.ShouldBeFalse();
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void Leere_Statements_werden_abgelehnt(string? sql)
|
||||
public void Empty_statements_are_rejected(string? sql)
|
||||
{
|
||||
SqlGuard.Inspect(sql, Allowed).IsValid.ShouldBeFalse();
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("SELECT * FROM prices JOIN signals ON signals.ticker = prices.ticker")]
|
||||
[InlineData("select * from PRICES")]
|
||||
[InlineData("SELECT * FROM prices;")]
|
||||
public void Erlaubte_Leseabfragen_gehen_durch(string sql)
|
||||
public void Allowed_read_queries_go_through(string sql)
|
||||
{
|
||||
var result = Inspect(sql);
|
||||
|
||||
@@ -130,7 +130,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("SELECT * FROM prices WHERE note = 'update'")]
|
||||
[InlineData("SELECT * FROM prices WHERE kommentar = 'bitte delete beachten'")]
|
||||
[InlineData("SELECT * FROM prices WHERE aktion = 'drop'")]
|
||||
public void Harmlose_Schluesselwoerter_in_Werten_gelten_nicht_als_Schreibzugriff(string sql)
|
||||
public void Harmless_keywords_in_values_do_not_count_as_write_access(string sql)
|
||||
{
|
||||
// The old substring test wrongly classified these queries as write or
|
||||
// structure access and blocked them for read-only agents.
|
||||
@@ -147,7 +147,7 @@ public sealed class SqlGuardTests
|
||||
[InlineData("DROP TABLE prices", SqlOperation.Schema)]
|
||||
[InlineData("ALTER TABLE prices ADD COLUMN x INT", SqlOperation.Schema)]
|
||||
[InlineData("TRUNCATE TABLE prices", SqlOperation.Schema)]
|
||||
public void Die_Operation_wird_am_ersten_Schluesselwort_bestimmt(string sql, SqlOperation expected)
|
||||
public void The_operation_is_determined_by_the_first_keyword(string sql, SqlOperation expected)
|
||||
{
|
||||
var result = Inspect(sql);
|
||||
|
||||
@@ -156,7 +156,7 @@ public sealed class SqlGuardTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Schema_qualifizierte_Namen_werden_erkannt()
|
||||
public void Schema_qualified_names_are_recognised()
|
||||
{
|
||||
var result = Inspect("SELECT * FROM crypto.prices WHERE id = 1");
|
||||
|
||||
@@ -164,7 +164,7 @@ public sealed class SqlGuardTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Der_Fehlertext_nennt_die_abgelehnte_Tabelle_und_die_erlaubten()
|
||||
public void The_error_text_names_the_rejected_table_and_the_allowed_ones()
|
||||
{
|
||||
var result = Inspect("SELECT * FROM geheim");
|
||||
|
||||
@@ -173,7 +173,7 @@ public sealed class SqlGuardTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Escaptes_Apostroph_im_Literal_bricht_die_Erkennung_nicht()
|
||||
public void Escaped_apostrophe_in_the_literal_does_not_break_detection()
|
||||
{
|
||||
var result = Inspect("SELECT * FROM prices WHERE name = 'O''Brien'");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user