Added a check for the characters of ERI usernames, tokens, and passwords (#1228)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-24 18:47:44 +01:00
1 parent e5a7f5423f
commit 9b4d07552d
16 files changed
+985 -18

No files matched your search

@@ -25234,6 +25234,66 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876"]
-- Please enter the secret necessary for authentication. -- Please enter the secret necessary for authentication.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876::INFORMAL"] = "Please enter the secret necessary for authentication." UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876::INFORMAL"] = "Please enter the secret necessary for authentication."
-- The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1126605556"] = "The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department."
-- The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1126605556::INFORMAL"] = "The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department."
-- The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1321099029"] = "The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1321099029::INFORMAL"] = "The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2361316190"] = "The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token."
-- The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2361316190::INFORMAL"] = "The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token."
-- The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2819602693"] = "The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2819602693::INFORMAL"] = "The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2930207847"] = "The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again."
-- The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2930207847::INFORMAL"] = "The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again."
-- The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3440410256"] = "The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department."
-- The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3440410256::INFORMAL"] = "The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department."
-- The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3690718143"] = "The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again."
-- The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3690718143::INFORMAL"] = "The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again."
-- The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3718710191"] = "The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token."
-- The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3718710191::INFORMAL"] = "The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token."
-- The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T4013716977"] = "The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T4013716977::INFORMAL"] = "The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T588839531"] = "The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again."
-- The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T588839531::INFORMAL"] = "The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again."
-- AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG. -- AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T1578559061"] = "AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG." UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T1578559061"] = "AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG."
@@ -198,7 +198,7 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
Name = this.dataName, Name = this.dataName,
Hostname = cleanedHostname.EndsWith('/') ? cleanedHostname[..^1] : cleanedHostname, Hostname = cleanedHostname.EndsWith('/') ? cleanedHostname[..^1] : cleanedHostname,
AuthMethod = this.dataAuthMethod, AuthMethod = this.dataAuthMethod,
Username = this.dataUsername, Username = ERICredentialValidation.Normalize(this.dataUsername),
UsernamePasswordMode = DataSourceERIUsernamePasswordMode.USER_MANAGED, UsernamePasswordMode = DataSourceERIUsernamePasswordMode.USER_MANAGED,
Type = DataSourceType.ERI_V1, Type = DataSourceType.ERI_V1,
SecurityPolicy = this.dataSecurityPolicy, SecurityPolicy = this.dataSecurityPolicy,
@@ -389,8 +389,11 @@ public partial class DataSourceERI_V1Dialog : MSGComponentBase, ISecretId
var addedDataSource = this.CreateDataSource(); var addedDataSource = this.CreateDataSource();
if (!string.IsNullOrWhiteSpace(this.dataSecret)) if (!string.IsNullOrWhiteSpace(this.dataSecret))
{ {
// Store the secret in the OS secure storage: //
var storeResponse = await this.RustService.SetSecret(this, this.dataSecret, SecretStoreType.DATA_SOURCE); // Store the secret in the OS secure storage, without the whitespace around it: it goes
// to the ERI server in an HTTP header, which drops that whitespace anyway:
//
var storeResponse = await this.RustService.SetSecret(this, ERICredentialValidation.Normalize(this.dataSecret), SecretStoreType.DATA_SOURCE);
if (!storeResponse.Success) if (!storeResponse.Success)
{ {
this.dataSecretStorageIssue = string.Format(TA("Failed to store the auth. secret in the operating system. The message was: {0}. Please try again."), storeResponse.Issue); this.dataSecretStorageIssue = string.Format(TA("Failed to store the auth. secret in the operating system. The message was: {0}. Please try again."), storeResponse.Issue);
@@ -9358,7 +9358,7 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3525663993"] = "In
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3549650120"] = "Noch keine Datenquellen konfiguriert." UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3549650120"] = "Noch keine Datenquellen konfiguriert."
-- Export Access Token? -- Export Access Token?
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3595669127"] = "Zugriffstoken exportieren?" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3595669127"] = "Zugangstoken exportieren?"
-- Local data sources refresh when files change. -- Local data sources refresh when files change.
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3687976654"] = "Lokale Datenquellen werden aktualisiert, wenn sich Dateien ändern." UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3687976654"] = "Lokale Datenquellen werden aktualisiert, wenn sich Dateien ändern."
@@ -9373,10 +9373,10 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3831281036"] = "ER
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3865031940"] = "Aktionen" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T3865031940"] = "Aktionen"
-- This ERI data source has an access token configured. Do you want to include the encrypted access token in the export? Note: The recipient will need the same encryption secret to use the access token. -- This ERI data source has an access token configured. Do you want to include the encrypted access token in the export? Note: The recipient will need the same encryption secret to use the access token.
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T4027572258"] = "Für diese ERI-Datenquelle ist ein Zugriffstoken konfiguriert. Möchten Sie das verschlüsselte Zugriffstoken in den Export aufnehmen? Hinweis: Der Empfänger benötigt dasselbe Geheimnis für die Verschlüsselung, um das Zugriffstoken verwenden zu können." UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T4027572258"] = "Für diese ERI-Datenquelle ist ein Zugangstoken konfiguriert. Möchten Sie das verschlüsselte Zugangstoken in den Export aufnehmen? Hinweis: Der Empfänger benötigt dasselbe Geheimnis für die Verschlüsselung, um das Zugangstoken verwenden zu können."
-- This ERI data source has an access token configured. Do you want to include the encrypted access token in the export? Note: The recipient will need the same encryption secret to use the access token. -- This ERI data source has an access token configured. Do you want to include the encrypted access token in the export? Note: The recipient will need the same encryption secret to use the access token.
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T4027572258::INFORMAL"] = "Für diese ERI-Datenquelle ist ein Zugriffstoken konfiguriert. Möchtest du das verschlüsselte Zugriffstoken in den Export aufnehmen? Hinweis: Der Empfänger benötigt dasselbe Geheimnis für die Verschlüsselung, um das Zugriffstoken verwenden zu können." UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T4027572258::INFORMAL"] = "Für diese ERI-Datenquelle ist ein Zugangstoken konfiguriert. Möchtest du das verschlüsselte Zugangstoken in den Export aufnehmen? Hinweis: Der Empfänger benötigt dasselbe Geheimnis für die Verschlüsselung, um das Zugangstoken verwenden zu können."
-- Waiting for indexing status -- Waiting for indexing status
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T4108252513"] = "Warten auf Indexierungsstatus" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::DATASOURCEMANAGEMENT::T4108252513"] = "Warten auf Indexierungsstatus"
@@ -25236,6 +25236,66 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876"]
-- Please enter the secret necessary for authentication. -- Please enter the secret necessary for authentication.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876::INFORMAL"] = "Bitte gib das für die Authentifizierung benötigte Geheimnis ein." UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876::INFORMAL"] = "Bitte gib das für die Authentifizierung benötigte Geheimnis ein."
-- The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1126605556"] = "Der Benutzername enthält das Zeichen „{0}“, das der ERI-Server nicht empfangen kann: Übertragen werden nur Buchstaben ohne Akzente, Ziffern, Leerzeichen und gängige Satzzeichen. Bitte überprüfen Sie den Benutzernamen. Falls er tatsächlich ein solches Zeichen enthält, wenden Sie sich bitte an Ihre IT-Abteilung."
-- The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1126605556::INFORMAL"] = "Der Benutzername enthält das Zeichen „{0}“, das der ERI-Server nicht empfangen kann: Übertragen werden nur Buchstaben ohne Akzente, Ziffern, Leerzeichen und gängige Satzzeichen. Bitte überprüfe den Benutzernamen. Falls er tatsächlich ein solches Zeichen enthält, wende dich bitte an deine IT-Abteilung."
-- The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1321099029"] = "Das Passwort der Datenquelle „{0}“ enthält ein Zeichen, das der ERI-Server nicht empfangen kann, etwa einen Umlaut, einen Zeilenumbruch oder ein unsichtbares Zeichen. Bitte geben Sie das Passwort in den Einstellungen der Datenquelle erneut ein. Wenn Ihre Organisation die Datenquelle bereitstellt, wenden Sie sich bitte an Ihre IT-Abteilung."
-- The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1321099029::INFORMAL"] = "Das Passwort der Datenquelle „{0}“ enthält ein Zeichen, das der ERI-Server nicht empfangen kann, etwa einen Umlaut, einen Zeilenumbruch oder ein unsichtbares Zeichen. Bitte gib das Passwort in den Einstellungen der Datenquelle erneut ein. Wenn deine Organisation die Datenquelle bereitstellt, wende dich bitte an deine IT-Abteilung."
-- The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2361316190"] = "Das Zugangstoken enthält ein Leerzeichen oder einen Zeilenumbruch. Beides kann in einem Zugangstoken nicht vorkommen. Bitte überprüfen Sie, ob Sie mehr als nur das Token kopiert haben."
-- The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2361316190::INFORMAL"] = "Das Zugangstoken enthält ein Leerzeichen oder einen Zeilenumbruch. Beides kann in einem Zugangstoken nicht vorkommen. Bitte überprüfe, ob du mehr als nur das Token kopiert hast."
-- The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2819602693"] = "Das Zugangstoken der Datenquelle „{0}“ enthält ein Zeichen, das in einem Zugangstoken nicht vorkommen kann, etwa einen Zeilenumbruch oder ein unsichtbares Zeichen. Bitte geben Sie das Token in den Einstellungen der Datenquelle erneut ein. Wenn Ihre Organisation die Datenquelle bereitstellt, wenden Sie sich bitte an Ihre IT-Abteilung."
-- The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2819602693::INFORMAL"] = "Das Zugangstoken der Datenquelle „{0}“ enthält ein Zeichen, das in einem Zugangstoken nicht vorkommen kann, etwa einen Zeilenumbruch oder ein unsichtbares Zeichen. Bitte gib das Token in den Einstellungen der Datenquelle erneut ein. Wenn deine Organisation die Datenquelle bereitstellt, wende dich bitte an deine IT-Abteilung."
-- The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2930207847"] = "Das Zugangstoken enthält ein unsichtbares Zeichen. Solche Zeichen kommen oft mit, wenn Sie Text von einer Webseite oder aus einem Dokument kopieren. Bitte löschen Sie das Token und geben Sie es erneut ein."
-- The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2930207847::INFORMAL"] = "Das Zugangstoken enthält ein unsichtbares Zeichen. Solche Zeichen kommen oft mit, wenn du Text von einer Webseite oder aus einem Dokument kopierst. Bitte lösche das Token und gib es erneut ein."
-- The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3440410256"] = "Das Passwort enthält ein Zeichen, das der ERI-Server nicht empfangen kann, etwa einen Umlaut, ein „ß“ oder ein typografisches Anführungszeichen: Übertragen werden nur Buchstaben ohne Akzente, Ziffern, Leerzeichen und gängige Satzzeichen. Bitte überprüfen Sie das Passwort. Falls es tatsächlich ein solches Zeichen enthält, wenden Sie sich bitte an Ihre IT-Abteilung."
-- The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3440410256::INFORMAL"] = "Das Passwort enthält ein Zeichen, das der ERI-Server nicht empfangen kann, etwa einen Umlaut, ein „ß“ oder ein typografisches Anführungszeichen: Übertragen werden nur Buchstaben ohne Akzente, Ziffern, Leerzeichen und gängige Satzzeichen. Bitte überprüfe das Passwort. Falls es tatsächlich ein solches Zeichen enthält, wende dich bitte an deine IT-Abteilung."
-- The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3690718143"] = "Das Passwort enthält einen Zeilenumbruch, einen Tabulator, ein besonderes Leerzeichen wie das geschützte Leerzeichen oder ein unsichtbares Zeichen. Solche Zeichen kann der ERI-Server nicht empfangen. Normale Leerzeichen sind in Ordnung. Bitte geben Sie das Passwort erneut ein."
-- The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3690718143::INFORMAL"] = "Das Passwort enthält einen Zeilenumbruch, einen Tabulator, ein besonderes Leerzeichen wie das geschützte Leerzeichen oder ein unsichtbares Zeichen. Solche Zeichen kann der ERI-Server nicht empfangen. Normale Leerzeichen sind in Ordnung. Bitte gib das Passwort erneut ein."
-- The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3718710191"] = "Das Zugangstoken enthält das Zeichen „{0}“, das in einem Zugangstoken nicht vorkommen kann. Textverarbeitungsprogramme machen zum Beispiel aus Anführungszeichen und Bindestrichen solche Zeichen. Bitte überprüfen Sie das Token."
-- The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3718710191::INFORMAL"] = "Das Zugangstoken enthält das Zeichen „{0}“, das in einem Zugangstoken nicht vorkommen kann. Textverarbeitungsprogramme machen zum Beispiel aus Anführungszeichen und Bindestrichen solche Zeichen. Bitte überprüfe das Token."
-- The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T4013716977"] = "Der Benutzername für die Datenquelle „{0}“ enthält ein Zeichen, das der ERI-Server nicht empfangen kann, etwa einen Umlaut. Bitte überprüfen Sie den Benutzernamen in den Einstellungen der Datenquelle. Wenn Ihre Organisation die Datenquelle bereitstellt, wenden Sie sich bitte an Ihre IT-Abteilung."
-- The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T4013716977::INFORMAL"] = "Der Benutzername für die Datenquelle „{0}“ enthält ein Zeichen, das der ERI-Server nicht empfangen kann, etwa einen Umlaut. Bitte überprüfe den Benutzernamen in den Einstellungen der Datenquelle. Wenn deine Organisation die Datenquelle bereitstellt, wende dich bitte an deine IT-Abteilung."
-- The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T588839531"] = "Der Benutzername enthält einen Zeilenumbruch, einen Tabulator, ein besonderes Leerzeichen wie das geschützte Leerzeichen oder ein unsichtbares Zeichen. Solche Zeichen kann der ERI-Server nicht empfangen. Normale Leerzeichen sind in Ordnung. Bitte geben Sie den Benutzernamen erneut ein."
-- The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T588839531::INFORMAL"] = "Der Benutzername enthält einen Zeilenumbruch, einen Tabulator, ein besonderes Leerzeichen wie das geschützte Leerzeichen oder ein unsichtbares Zeichen. Solche Zeichen kann der ERI-Server nicht empfangen. Normale Leerzeichen sind in Ordnung. Bitte gib den Benutzernamen erneut ein."
-- AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG. -- AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T1578559061"] = "AI Studio kann keine Bilder im Format {0} an ein KI-Modell übergeben. Bitte konvertieren Sie das Bild in JPG oder PNG." UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T1578559061"] = "AI Studio kann keine Bilder im Format {0} an ein KI-Modell übergeben. Bitte konvertieren Sie das Bild in JPG oder PNG."
@@ -25236,6 +25236,66 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876"]
-- Please enter the secret necessary for authentication. -- Please enter the secret necessary for authentication.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876::INFORMAL"] = "Please enter the secret necessary for authentication." UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T968385876::INFORMAL"] = "Please enter the secret necessary for authentication."
-- The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1126605556"] = "The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department."
-- The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1126605556::INFORMAL"] = "The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department."
-- The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1321099029"] = "The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T1321099029::INFORMAL"] = "The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2361316190"] = "The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token."
-- The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2361316190::INFORMAL"] = "The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token."
-- The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2819602693"] = "The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2819602693::INFORMAL"] = "The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2930207847"] = "The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again."
-- The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T2930207847::INFORMAL"] = "The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again."
-- The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3440410256"] = "The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department."
-- The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3440410256::INFORMAL"] = "The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department."
-- The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3690718143"] = "The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again."
-- The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3690718143::INFORMAL"] = "The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again."
-- The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3718710191"] = "The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token."
-- The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T3718710191::INFORMAL"] = "The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token."
-- The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T4013716977"] = "The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T4013716977::INFORMAL"] = "The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department."
-- The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T588839531"] = "The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again."
-- The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::ERICREDENTIALVALIDATION::T588839531::INFORMAL"] = "The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again."
-- AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG. -- AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T1578559061"] = "AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG." UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T1578559061"] = "AI Studio cannot give {0} images to an AI model. Please convert the image to JPG or PNG."
@@ -326,6 +326,19 @@ public record struct DataSourceERI_V1: IERIDataSource
LOGGER.LogWarning($"The configured data source {idx} must specify a username. (Plugin ID: {configPluginId})"); LOGGER.LogWarning($"The configured data source {idx} must specify a username. (Plugin ID: {configPluginId})");
return false; return false;
} }
//
// The username goes to the ERI server in an HTTP header, which carries nothing but ASCII.
// Nobody on the device could change it, so the data source would fail with every search:
//
var usernameIssue = ERICredentialValidation.CheckUsername(username);
if (usernameIssue.IsProblem)
{
LOGGER.LogWarning($"The username of the configured data source {idx} contains a character which the ERI server cannot receive ({usernameIssue.Kind}). (Plugin ID: {configPluginId})");
return false;
}
username = ERICredentialValidation.Normalize(username);
} }
dataSource = new DataSourceERI_V1 dataSource = new DataSourceERI_V1
@@ -451,6 +464,18 @@ public record struct DataSourceERI_V1: IERIDataSource
return false; return false;
} }
//
// The secret goes to the ERI server in an HTTP header, as the username does. One which the
// header cannot carry counts like one which cannot be decrypted. A dry run checks it as well,
// so that it writes the warning, too:
//
var secretIssue = ERICredentialValidation.CheckSecret(dataSource.AuthMethod, decryptedSecret);
if (secretIssue.IsProblem)
{
LOGGER.LogWarning($"The {secretFieldName} for data source {idx} contains a character which the ERI server cannot receive ({secretIssue.Kind}). (Plugin ID: {configPluginId})");
return false;
}
// //
// A dry run only checks the configuration, so it queues nothing: the start which follows it // A dry run only checks the configuration, so it queues nothing: the start which follows it
// would otherwise store the secret once more for every dry run before it: // would otherwise store the secret once more for every dry run before it:
@@ -461,7 +486,7 @@ public record struct DataSourceERI_V1: IERIDataSource
PendingEnterpriseSecrets.Add(new( PendingEnterpriseSecrets.Add(new(
$"{ISecretId.ENTERPRISE_KEY_PREFIX}::{dataSource.Id}", $"{ISecretId.ENTERPRISE_KEY_PREFIX}::{dataSource.Id}",
dataSource.Name, dataSource.Name,
decryptedSecret, ERICredentialValidation.Normalize(decryptedSecret),
SecretStoreType.DATA_SOURCE)); SecretStoreType.DATA_SOURCE));
LOGGER.LogDebug($"Successfully decrypted the {secretFieldName} for data source {idx}. It will be stored in the OS keyring. (Plugin ID: {configPluginId})"); LOGGER.LogDebug($"Successfully decrypted the {secretFieldName} for data source {idx}. It will be stored in the OS keyring. (Plugin ID: {configPluginId})");
return true; return true;
@@ -1,3 +1,4 @@
using System.Net.Http.Headers;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@@ -6,6 +7,7 @@ using AIStudio.Settings.DataModel;
using AIStudio.Tools.ERIClient.DataModel; using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.PluginSystem; using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Services; using AIStudio.Tools.Services;
using AIStudio.Tools.Validation;
namespace AIStudio.Tools.ERIClient; namespace AIStudio.Tools.ERIClient;
@@ -134,12 +136,22 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
else else
password = temporarySecret; password = temporarySecret;
//
// Both values go to the server in HTTP headers, which carry nothing but ASCII. A value
// which cannot be sent fails here, with a message which names neither of them:
//
if (ERICredentialValidation.CheckUsername(username).IsProblem)
return UnusableCredential(ERICredentialValidation.GetUnusableUsernameMessage(this.DataSource.Name));
if (ERICredentialValidation.CheckSecret(AuthMethod.USERNAME_PASSWORD, password).IsProblem)
return UnusableCredential(ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.USERNAME_PASSWORD, this.DataSource.Name));
using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}")) using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}"))
{ {
// We must send both values inside the header. The username field is named 'user'. // We must send both values inside the header. The username field is named 'user'.
// The password field is named 'password'. // The password field is named 'password'.
request.Headers.Add("user", username); request.Headers.Add("user", ERICredentialValidation.Normalize(username));
request.Headers.Add("password", password); request.Headers.Add("password", ERICredentialValidation.Normalize(password));
using var usernamePasswordAuthResponse = await this.HttpClient.SendAsync(request, cancellationToken); using var usernamePasswordAuthResponse = await this.HttpClient.SendAsync(request, cancellationToken);
if(!usernamePasswordAuthResponse.IsSuccessStatusCode) if(!usernamePasswordAuthResponse.IsSuccessStatusCode)
@@ -188,9 +200,13 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
else else
token = temporarySecret; token = temporarySecret;
if (ERICredentialValidation.CheckSecret(AuthMethod.TOKEN, token).IsProblem)
return UnusableCredential(ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.TOKEN, this.DataSource.Name));
using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}")) using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}"))
{ {
request.Headers.Add("Authorization", $"Bearer {token}"); // Typed, so that .NET does not parse the header and quote the token when it cannot:
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", ERICredentialValidation.Normalize(token));
using var tokenAuthResponse = await this.HttpClient.SendAsync(request, cancellationToken); using var tokenAuthResponse = await this.HttpClient.SendAsync(request, cancellationToken);
if(!tokenAuthResponse.IsSuccessStatusCode) if(!tokenAuthResponse.IsSuccessStatusCode)
@@ -506,4 +522,10 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
} }
#endregion #endregion
private static APIResponse<AuthResponse> UnusableCredential(string message) => new()
{
Successful = false,
Message = message,
};
} }
@@ -12,7 +12,8 @@ public enum APIKeyIssueKind
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// No provider issues keys with whitespace, so the user most likely copied more than the key, /// No provider issues keys with whitespace, so the user most likely copied more than the key,
/// e.g., two lines of a table or the key together with its name. /// e.g., two lines of a table or the key together with its name. Values which people choose
/// themselves, such as a password, may contain a plain space, but no other whitespace.
/// </remarks> /// </remarks>
WHITESPACE, WHITESPACE,
@@ -58,12 +58,25 @@ public static class APIKeyValidation
/// </remarks> /// </remarks>
/// <param name="key">The key as the user entered it.</param> /// <param name="key">The key as the user entered it.</param>
/// <returns>The first issue, or NONE when the key can be sent.</returns> /// <returns>The first issue, or NONE when the key can be sent.</returns>
public static APIKeyIssue Check(string? key) public static APIKeyIssue Check(string? key) => Check(key, allowsSpaces: false);
/// <summary>
/// Finds the first character of a value for an HTTP header which cannot be sent.
/// </summary>
/// <remarks>
/// The same check as for an API key, for values which people choose themselves, such as the
/// password of an ERI server: there, a space inside the value is fine and goes into the header
/// as it is. Every other whitespace inside the value is still an issue, the no-break space included.
/// </remarks>
/// <param name="value">The value as the user entered it.</param>
/// <param name="allowsSpaces">Whether a plain space inside the value is fine.</param>
/// <returns>The first issue, or NONE when the value can be sent.</returns>
public static APIKeyIssue Check(string? value, bool allowsSpaces)
{ {
var characters = StringInfo.GetTextElementEnumerator(Normalize(key)); var characters = StringInfo.GetTextElementEnumerator(Normalize(value));
while (characters.MoveNext()) while (characters.MoveNext())
{ {
var issue = CheckCharacter(characters.GetTextElement()); var issue = CheckCharacter(characters.GetTextElement(), allowsSpaces);
if (issue.IsProblem) if (issue.IsProblem)
return issue; return issue;
} }
@@ -124,9 +137,9 @@ public static class APIKeyValidation
/// <returns>The message.</returns> /// <returns>The message.</returns>
public static string GetUnusableKeyMessage(string ownerName) => string.Format(TA("The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department."), ownerName); public static string GetUnusableKeyMessage(string ownerName) => string.Format(TA("The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department."), ownerName);
private static APIKeyIssue CheckCharacter(string character) private static APIKeyIssue CheckCharacter(string character, bool allowsSpaces)
{ {
if (character.Length is 1 && character[0] is >= '!' and <= '~') if (character.Length is 1 && (character[0] is >= '!' and <= '~' || (allowsSpaces && character[0] is ' ')))
return APIKeyIssue.NONE; return APIKeyIssue.NONE;
// //
@@ -92,7 +92,8 @@ public sealed class DataSourceValidation
if(string.IsNullOrWhiteSpace(username)) if(string.IsNullOrWhiteSpace(username))
return TB("The username must not be empty."); return TB("The username must not be empty.");
return null; // The username goes to the ERI server in an HTTP header, which carries nothing but ASCII:
return ERICredentialValidation.ValidateUsername(username);
} }
public string? ValidatingSecret(string secret) public string? ValidatingSecret(string secret)
@@ -114,7 +115,8 @@ public sealed class DataSourceValidation
_ => TA("Please enter the secret necessary for authentication.") _ => TA("Please enter the secret necessary for authentication.")
}; };
return null; // Like the username, the password or the token goes to the ERI server in an HTTP header:
return ERICredentialValidation.ValidateSecret(authMethod, secret);
} }
public string? ValidateRetrievalProcess(RetrievalInfo retrievalInfo) public string? ValidateRetrievalProcess(RetrievalInfo retrievalInfo)
@@ -0,0 +1,113 @@
using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools.Validation;
/// <summary>
/// Checks whether the username, the password, or the access token of an ERI data source can be sent to its server at all.
/// </summary>
/// <remarks>
/// <para>
/// ERI v1 sends all three in HTTP headers, which carry nothing but ASCII. The check is the one for API
/// keys in APIKeyValidation: the whitespace around a value goes, since HTTP drops it anyway, and
/// everything else is reported instead of removed. An access token is checked exactly like an API key.
/// A password and a username may contain spaces, since people choose them, but no other whitespace.
/// </para>
/// <para>
/// A message about a password never names the character: the field hides the password, and the
/// message would show a part of it. A message for a stored value names no character at all, since
/// the callers of the ERI client write such messages to the log.
/// </para>
/// </remarks>
public static class ERICredentialValidation
{
private static string TA(string fallbackEN) => I18N.I.TA(fallbackEN, typeof(ERICredentialValidation).Namespace, nameof(ERICredentialValidation));
/// <summary>
/// Removes the whitespace around a username, a password, or an access token.
/// </summary>
/// <param name="value">The value as the user entered it.</param>
/// <returns>The value without the whitespace around it, or an empty string for no value.</returns>
public static string Normalize(string? value) => APIKeyValidation.Normalize(value);
/// <summary>
/// Finds the first character of a password or an access token which cannot be sent.
/// </summary>
/// <param name="authMethod">How the data source signs in.</param>
/// <param name="secret">The password or the access token.</param>
/// <returns>The first issue, or NONE when the secret can be sent or the auth method needs none.</returns>
public static APIKeyIssue CheckSecret(AuthMethod authMethod, string? secret) => authMethod switch
{
AuthMethod.TOKEN => APIKeyValidation.Check(secret),
AuthMethod.USERNAME_PASSWORD => APIKeyValidation.Check(secret, allowsSpaces: true),
_ => APIKeyIssue.NONE,
};
/// <summary>
/// Finds the first character of a username which cannot be sent.
/// </summary>
/// <param name="username">The username.</param>
/// <returns>The first issue, or NONE when the username can be sent.</returns>
public static APIKeyIssue CheckUsername(string? username) => APIKeyValidation.Check(username, allowsSpaces: true);
/// <summary>
/// Checks a password or an access token the user is entering.
/// </summary>
/// <param name="authMethod">How the data source signs in.</param>
/// <param name="secret">The password or the access token as the user entered it.</param>
/// <returns>What is wrong with the secret, or null when it can be sent.</returns>
public static string? ValidateSecret(AuthMethod authMethod, string? secret)
{
var issue = CheckSecret(authMethod, secret);
if (!issue.IsProblem)
return null;
return authMethod is AuthMethod.TOKEN ? GetTokenMessage(issue) : GetPasswordMessage(issue);
}
/// <summary>
/// Checks a username the user is entering.
/// </summary>
/// <param name="username">The username as the user entered it.</param>
/// <returns>What is wrong with the username, or null when it can be sent.</returns>
public static string? ValidateUsername(string? username)
{
var issue = CheckUsername(username);
return issue.IsProblem ? GetUsernameMessage(issue) : null;
}
/// <summary>
/// Tells the user that the stored password or access token of a data source cannot be sent.
/// </summary>
/// <param name="authMethod">How the data source signs in.</param>
/// <param name="dataSourceName">The name of the data source.</param>
/// <returns>The message, which names no character.</returns>
public static string GetUnusableSecretMessage(AuthMethod authMethod, string dataSourceName) => authMethod is AuthMethod.TOKEN
? string.Format(TA("The access token of the data source '{0}' contains a character which an access token cannot contain, such as a line break or an invisible character. Please enter the token again in the settings of the data source. If your organization provides the data source, please contact your IT department."), dataSourceName)
: string.Format(TA("The password of the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut, a line break, or an invisible character. Please enter the password again in the settings of the data source. If your organization provides the data source, please contact your IT department."), dataSourceName);
/// <summary>
/// Tells the user that the username for a data source cannot be sent.
/// </summary>
/// <param name="dataSourceName">The name of the data source.</param>
/// <returns>The message, which names no character.</returns>
public static string GetUnusableUsernameMessage(string dataSourceName) => string.Format(TA("The username for the data source '{0}' contains a character which the ERI server cannot receive, such as an umlaut. Please check the username in the settings of the data source. If your organization provides the data source, please contact your IT department."), dataSourceName);
private static string GetTokenMessage(APIKeyIssue issue) => issue.Kind switch
{
APIKeyIssueKind.WHITESPACE => TA("The access token contains a space or a line break, which an access token cannot contain. Please check whether you copied more than the token."),
APIKeyIssueKind.INVISIBLE_CHARACTER => TA("The access token contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the token and enter it again."),
APIKeyIssueKind.NON_ASCII_CHARACTER => string.Format(TA("The access token contains the character '{0}', which an access token cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the token."), issue.Character),
_ => string.Empty,
};
private static string GetPasswordMessage(APIKeyIssue issue) => issue.Kind is APIKeyIssueKind.NON_ASCII_CHARACTER
? TA("The password contains a character which the ERI server cannot receive, such as an umlaut, 'ß', or a typographic quotation mark: only letters without accents, digits, spaces, and common punctuation get through. Please check the password. If it really contains such a character, please contact your IT department.")
: TA("The password contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the password again.");
private static string GetUsernameMessage(APIKeyIssue issue) => issue.Kind is APIKeyIssueKind.NON_ASCII_CHARACTER
? string.Format(TA("The username contains the character '{0}', which the ERI server cannot receive: only letters without accents, digits, spaces, and common punctuation get through. Please check the username. If it really contains such a character, please contact your IT department."), issue.Character)
: TA("The username contains a line break, a tab, a special space such as a non-breaking space, or an invisible character, which the ERI server cannot receive. Ordinary spaces are fine. Please enter the username again.");
}
@@ -27,6 +27,9 @@
- Improved entering API keys: AI Studio removes spaces and line breaks around a pasted key and tells you right away when a key contains a character which an API key cannot contain, such as an invisible character copied from a web page or a typographic quotation mark. - Improved entering API keys: AI Studio removes spaces and line breaks around a pasted key and tells you right away when a key contains a character which an API key cannot contain, such as an invisible character copied from a web page or a typographic quotation mark.
- Improved the message when a stored API key contains a character which an API key cannot contain, such as a line break: AI Studio now asks you to enter the key again instead of showing a technical error. - Improved the message when a stored API key contains a character which an API key cannot contain, such as a line break: AI Studio now asks you to enter the key again instead of showing a technical error.
- Improved the API keys which organizations provide through configuration plugins: AI Studio removes spaces and line breaks around them and leaves out a key with characters which an API key cannot contain, noting this in the log. - Improved the API keys which organizations provide through configuration plugins: AI Studio removes spaces and line breaks around them and leaves out a key with characters which an API key cannot contain, noting this in the log.
- Improved signing in to ERI data sources: AI Studio tells you right away when a username, access token, or password contains a character which the ERI server cannot receive, such as an umlaut in a password, instead of showing a technical error. Spaces inside a password remain possible.
- Improved the ERI data sources which organizations provide through configuration plugins: AI Studio removes spaces and line breaks around their tokens and passwords and leaves out a data source whose username, token, or password contains a character which the ERI server cannot receive, noting this in the log.
- Improved the messages about failed requests to ERI servers, which no longer repeat the values sent along with a request.
- Improved the Flatpak version of AI Studio for Linux: it now runs on the GNOME 51 runtime, ships the same up-to-date version of .NET, and is built with the same up-to-date version of Rust as all other versions of AI Studio. - Improved the Flatpak version of AI Studio for Linux: it now runs on the GNOME 51 runtime, ships the same up-to-date version of .NET, and is built with the same up-to-date version of Rust as all other versions of AI Studio.
- Changed the icons of AI Studio to Lucide, an open-source icon set. All icons now share one style, and each feature shows the same icon wherever you meet it. - Changed the icons of AI Studio to Lucide, an open-source icon set. All icons now share one style, and each feature shows the same icon wherever you meet it.
- Fixed assistant plugins, which all appeared under "Installed Assistants" on the assistants page. Each one now appears under its own category, such as "Business", next to the built-in assistants of that category. - Fixed assistant plugins, which all appeared under "Installed Assistants" on the assistants page. Each one now appears under its own category, such as "Business", next to the built-in assistants of that category.
@@ -0,0 +1,212 @@
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
using AIStudio.Tools.ERIClient;
using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.Services;
using AIStudio.Tools.Validation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
namespace AIStudio.Tests.Tools;
/// <summary>
/// Checks that the ERI client sends no username, password, or access token which an HTTP header
/// cannot carry, and what it says instead.
/// </summary>
/// <remarks>
/// <para>
/// The data source points to port 1 of the own machine, where nothing listens: a request which the
/// client sends fails right away, with a message of its own. A message about the credentials thus
/// shows that the client stopped before sending. Nothing here asserts on the wording of a message:
/// I18N is process-wide state without a reset.
/// </para>
/// <para>
/// The messages of the client end up in the log. .NET quotes a header value in its exception only
/// when it parses the header and fails, as it does for an Authorization header with a line break
/// in the token. The other headers of ERI, i.e., user, password, and the session token, go unparsed,
/// and .NET names no value when it refuses them.
/// </para>
/// </remarks>
[TestFixture]
[NonParallelizable]
public sealed partial class ERIClientV1AuthenticationTests
{
private const string NAME = "Intranet";
// A part of each secret which no message could contain by chance, whatever its language:
private const string SECRET_PART = "Xq7";
private static readonly string ZERO_WIDTH_SPACE = ((char)0x200B).ToString();
private static readonly DataSourceERI_V1 UNREACHABLE = new()
{
Id = "44444444-4444-4444-4444-444444444444",
Name = NAME,
Type = DataSourceType.ERI_V1,
Hostname = "http://127.0.0.1",
Port = 1,
AuthMethod = AuthMethod.TOKEN,
SecurityPolicy = DataSourceSecurity.ALLOW_ANY,
MaxMatches = 10,
};
private RustService rustService = null!;
private ServiceProvider serviceProvider = null!;
private IServiceProvider previousServiceProvider = null!;
[SetUp]
public void PrepareServices()
{
this.rustService = new RustService("1", "unused");
var settingsManager = new SettingsManager(NullLogger<SettingsManager>.Instance, this.rustService);
this.previousServiceProvider = Program.SERVICE_PROVIDER;
this.serviceProvider = new ServiceCollection()
.AddSingleton(this.rustService)
.AddSingleton(settingsManager)
.AddLogging()
.BuildServiceProvider();
Program.SERVICE_PROVIDER = this.serviceProvider;
}
[TearDown]
public void RestoreApplicationState()
{
Program.SERVICE_PROVIDER = this.previousServiceProvider;
this.serviceProvider.Dispose();
this.rustService.Dispose();
}
private async Task<APIResponse<AuthResponse>> AuthenticateAsync(DataSourceERI_V1 dataSource, string secret)
{
using var client = new ERIClientV1(dataSource);
return await client.AuthenticateAsync(this.rustService, secret);
}
[Test]
public async Task ATokenWithAnInvisibleCharacterIsNotSent()
{
var response = await this.AuthenticateAsync(UNREACHABLE, $"tok{ZERO_WIDTH_SPACE}en-{SECRET_PART}");
using (Assert.EnterMultipleScope())
{
Assert.That(response.Successful, Is.False);
Assert.That(response.Message, Is.EqualTo(ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.TOKEN, NAME)));
Assert.That(response.Message, Does.Not.Contain(SECRET_PART));
}
}
[Test]
public async Task APasswordWithAnUmlautIsNotSent()
{
var dataSource = UNREACHABLE with { AuthMethod = AuthMethod.USERNAME_PASSWORD, Username = "max" };
var response = await this.AuthenticateAsync(dataSource, $"Grüße 2024 {SECRET_PART}");
using (Assert.EnterMultipleScope())
{
Assert.That(response.Successful, Is.False);
Assert.That(response.Message, Is.EqualTo(ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.USERNAME_PASSWORD, NAME)));
Assert.That(response.Message, Does.Not.Contain(SECRET_PART));
}
}
[Test]
public async Task AUsernameWithAnUmlautIsNotSent()
{
var dataSource = UNREACHABLE with { AuthMethod = AuthMethod.USERNAME_PASSWORD, Username = "jürgen" };
var response = await this.AuthenticateAsync(dataSource, "Mein Passwort");
using (Assert.EnterMultipleScope())
{
Assert.That(response.Successful, Is.False);
Assert.That(response.Message, Is.EqualTo(ERICredentialValidation.GetUnusableUsernameMessage(NAME)));
}
}
[Test]
public async Task APasswordWithSpacesIsSent()
{
var dataSource = UNREACHABLE with { AuthMethod = AuthMethod.USERNAME_PASSWORD, Username = "Max Mustermann" };
var response = await this.AuthenticateAsync(dataSource, " Mein Passwort\n");
string[] messagesAboutCredentials =
[
ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.USERNAME_PASSWORD, NAME),
ERICredentialValidation.GetUnusableUsernameMessage(NAME),
];
using (Assert.EnterMultipleScope())
{
Assert.That(response.Successful, Is.False, "Nothing listens on port 1.");
Assert.That(messagesAboutCredentials, Has.No.Member(response.Message), "The client has to send the request.");
}
}
[Test]
public async Task APasswordWithALineBreakIsNotQuoted()
{
var dataSource = UNREACHABLE with { AuthMethod = AuthMethod.USERNAME_PASSWORD, Username = "max" };
var response = await this.AuthenticateAsync(dataSource, $"Pass\n{SECRET_PART} 2024");
using (Assert.EnterMultipleScope())
{
Assert.That(response.Message, Is.EqualTo(ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.USERNAME_PASSWORD, NAME)));
Assert.That(response.Message, Does.Not.Contain(SECRET_PART));
}
}
[Test]
public async Task ATokenOfPrintableAsciiIsSent()
{
var response = await this.AuthenticateAsync(UNREACHABLE, "eyJhbGciOiJIUzI1NiJ9.e30.abc-_~+/=\n");
using (Assert.EnterMultipleScope())
{
Assert.That(response.Successful, Is.False, "Nothing listens on port 1.");
Assert.That(response.Message, Is.Not.EqualTo(ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.TOKEN, NAME)), "The client has to send the request.");
}
}
[Test]
public async Task ATokenWithALineBreakIsNotQuoted()
{
// Parsed as an Authorization header, this token made .NET quote it in its exception:
var response = await this.AuthenticateAsync(UNREACHABLE, $"tok\n{SECRET_PART}");
using (Assert.EnterMultipleScope())
{
Assert.That(response.Message, Is.EqualTo(ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.TOKEN, NAME)));
Assert.That(response.Message, Does.Not.Contain(SECRET_PART));
}
}
[Test]
public async Task ASessionTokenWithALineBreakIsNotQuoted()
{
using var server = new LoopbackERIServer($"Sitzung\n{SECRET_PART}");
using var client = new ERIClientV1(UNREACHABLE with { AuthMethod = AuthMethod.NONE, Port = server.Port });
var authentication = await client.AuthenticateAsync(this.rustService);
var securityRequirements = await client.GetSecurityRequirementsAsync();
using (Assert.EnterMultipleScope())
{
Assert.That(authentication.Successful, Is.True, "The server has to hand out its session token.");
Assert.That(securityRequirements.Successful, Is.False);
Assert.That(securityRequirements.Message, Is.Not.Empty);
Assert.That(securityRequirements.Message, Does.Not.Contain(SECRET_PART));
}
}
[Test]
public void NoERIClientParsesAnAuthorizationHeader()
{
var clientDirectory = Path.Combine(AppSourceDirectory(), "Tools", "ERIClient");
var files = Directory.EnumerateFiles(clientDirectory, "*.cs", SearchOption.AllDirectories)
.Where(path => ValidatedAuthorizationRegex().IsMatch(File.ReadAllText(path)))
.Select(path => Path.GetRelativePath(clientDirectory, path));
Assert.That(files, Is.Empty, "Headers.Add quotes an Authorization header it cannot parse, i.e., the token, in its exception; use AuthenticationHeaderValue.");
}
[GeneratedRegex(@"\.Headers\.Add\(\s*""Authorization""")]
private static partial Regex ValidatedAuthorizationRegex();
private static string AppSourceDirectory([CallerFilePath] string sourceFilePath = "") => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sourceFilePath)!, "..", "..", "MindWork AI Studio"));
}
+78
View File
@@ -0,0 +1,78 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.Json;
namespace AIStudio.Tests.Tools;
/// <summary>
/// A minimal ERI server on the loopback address, which signs every client in with the session token
/// the test names.
/// </summary>
/// <remarks>
/// POST /auth answers with that token, and every other request with an error, so that a test sees what
/// the client does with the token before it would need anything else of the server.
/// </remarks>
internal sealed class LoopbackERIServer : IDisposable
{
private readonly TcpListener listener = new(IPAddress.Loopback, 0);
private readonly CancellationTokenSource stop = new();
private readonly string sessionToken;
/// <param name="sessionToken">The session token the server hands out.</param>
public LoopbackERIServer(string sessionToken)
{
this.sessionToken = sessionToken;
this.listener.Start();
_ = this.ServeAsync();
}
public int Port => ((IPEndPoint)this.listener.LocalEndpoint).Port;
private async Task ServeAsync()
{
try
{
while (!this.stop.IsCancellationRequested)
{
using var client = await this.listener.AcceptTcpClientAsync(this.stop.Token);
await using var stream = client.GetStream();
var request = await ReadRequestHeadAsync(stream, this.stop.Token);
var response = request.StartsWith("POST /auth", StringComparison.Ordinal)
? Json($$"""{"success":true,"token":"{{JsonEncodedText.Encode(this.sessionToken)}}","message":null}""")
: "HTTP/1.1 500 Internal Server Error\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
await stream.WriteAsync(Encoding.UTF8.GetBytes(response), this.stop.Token);
}
}
catch (Exception exception) when (exception is OperationCanceledException or ObjectDisposedException or SocketException)
{
// The test is over.
}
}
private static string Json(string json) => $"HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: {Encoding.UTF8.GetByteCount(json)}\r\nConnection: close\r\n\r\n{json}";
private static async Task<string> ReadRequestHeadAsync(NetworkStream stream, CancellationToken token)
{
var head = new StringBuilder();
var buffer = new byte[1024];
while (!head.ToString().Contains("\r\n\r\n", StringComparison.Ordinal))
{
var read = await stream.ReadAsync(buffer, token);
if (read == 0)
break;
head.Append(Encoding.ASCII.GetString(buffer, 0, read));
}
return head.ToString();
}
public void Dispose()
{
this.stop.Cancel();
this.listener.Stop();
this.stop.Dispose();
}
}
@@ -74,6 +74,25 @@ public sealed class APIKeyValidationTests
[TestCase("\u3000")] [TestCase("\u3000")]
public void WhitespaceInsideTheKeyIsReported(string whitespace) => Assert.That(APIKeyValidation.Check($"sk-proj{whitespace}AbC123").Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE)); public void WhitespaceInsideTheKeyIsReported(string whitespace) => Assert.That(APIKeyValidation.Check($"sk-proj{whitespace}AbC123").Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE));
[Test]
public void AValueWhichAllowsSpacesKeepsThem()
{
using (Assert.EnterMultipleScope())
{
Assert.That(APIKeyValidation.Check("my secret phrase", allowsSpaces: true), Is.EqualTo(APIKeyIssue.NONE));
Assert.That(APIKeyValidation.Check(" my secret phrase\n", allowsSpaces: true), Is.EqualTo(APIKeyIssue.NONE), "The whitespace around the value goes, as for a key.");
Assert.That(APIKeyValidation.Check("my secret phrase", allowsSpaces: false).Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE));
Assert.That(APIKeyValidation.Check("my secret phrase").Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE), "A key allows no spaces.");
}
}
[TestCase("\t")]
[TestCase("\n")]
[TestCase("\r\n")]
[TestCase("\u00A0")]
[TestCase("\u3000")]
public void AValueWhichAllowsSpacesStillReportsOtherWhitespace(string whitespace) => Assert.That(APIKeyValidation.Check($"my{whitespace}secret", allowsSpaces: true).Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE));
[TestCase(0x200B)] [TestCase(0x200B)]
[TestCase(0x200D)] [TestCase(0x200D)]
[TestCase(0x2060)] [TestCase(0x2060)]
@@ -0,0 +1,87 @@
using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.Validation;
namespace AIStudio.Tests.Tools.Validation;
/// <summary>
/// Checks what the dialog of an ERI data source says about the username and the secret entered there.
/// </summary>
/// <remarks>
/// Nothing here asserts on the wording of a message: I18N is process-wide state without a reset.
/// The messages about characters are compared with those of ERICredentialValidation instead.
/// </remarks>
[TestFixture]
public sealed class DataSourceCredentialValidationTests
{
private const string STORAGE_ISSUE = "The keyring is locked.";
private static readonly string ZERO_WIDTH_SPACE = ((char)0x200B).ToString();
private static DataSourceValidation For(AuthMethod authMethod, string secretStorageIssue = "") => new()
{
GetAuthMethod = () => authMethod,
GetSecretStorageIssue = () => secretStorageIssue,
};
[TestCase(AuthMethod.NONE)]
[TestCase(AuthMethod.KERBEROS)]
public void AnAuthMethodWithoutASecretNeedsNone(AuthMethod authMethod)
{
using (Assert.EnterMultipleScope())
{
Assert.That(For(authMethod).ValidatingSecret(string.Empty), Is.Null);
Assert.That(For(authMethod).ValidatingSecret($"a{ZERO_WIDTH_SPACE}b"), Is.Null);
}
}
[TestCase(AuthMethod.TOKEN)]
[TestCase(AuthMethod.USERNAME_PASSWORD)]
public void AStorageIssueComesFirst(AuthMethod authMethod)
{
using (Assert.EnterMultipleScope())
{
Assert.That(For(authMethod, STORAGE_ISSUE).ValidatingSecret($"a{ZERO_WIDTH_SPACE}b"), Is.EqualTo(STORAGE_ISSUE));
Assert.That(For(authMethod, STORAGE_ISSUE).ValidatingSecret(string.Empty), Is.EqualTo(STORAGE_ISSUE));
}
}
[TestCase(AuthMethod.TOKEN)]
[TestCase(AuthMethod.USERNAME_PASSWORD)]
public void AMissingSecretIsReported(AuthMethod authMethod)
{
var message = For(authMethod).ValidatingSecret(" ");
using (Assert.EnterMultipleScope())
{
Assert.That(message, Is.Not.Null.And.Not.Empty);
Assert.That(message, Is.Not.EqualTo(ERICredentialValidation.ValidateSecret(authMethod, $"a{ZERO_WIDTH_SPACE}b")), "An empty field is no issue of its characters.");
}
}
[Test]
public void ATokenWithAnInvisibleCharacterIsReported()
{
var token = $"eyJhbGciOiJIUzI1NiJ9{ZERO_WIDTH_SPACE}.e30";
Assert.That(For(AuthMethod.TOKEN).ValidatingSecret(token), Is.Not.Null.And.EqualTo(ERICredentialValidation.ValidateSecret(AuthMethod.TOKEN, token)));
}
[Test]
public void APasswordWithAnUmlautIsReported() => Assert.That(For(AuthMethod.USERNAME_PASSWORD).ValidatingSecret("Grüße 2024"), Is.Not.Null.And.EqualTo(ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, "Grüße 2024")));
[Test]
public void APasswordWithSpacesIsAccepted() => Assert.That(For(AuthMethod.USERNAME_PASSWORD).ValidatingSecret("Mein Passwort"), Is.Null);
[Test]
public void AUsernameWithAnUmlautIsReported()
{
var validation = For(AuthMethod.USERNAME_PASSWORD);
using (Assert.EnterMultipleScope())
{
Assert.That(validation.ValidateUsername("jürgen"), Is.Not.Null.And.EqualTo(ERICredentialValidation.ValidateUsername("jürgen")));
Assert.That(validation.ValidateUsername("Max Mustermann"), Is.Null);
Assert.That(validation.ValidateUsername(" "), Is.Not.Null, "An empty username is still reported.");
}
}
[Test]
public void TheUsernameMattersOnlyForUsernameAndPassword() => Assert.That(For(AuthMethod.TOKEN).ValidateUsername("jürgen"), Is.Null);
}
@@ -0,0 +1,209 @@
using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.Validation;
namespace AIStudio.Tests.Tools.Validation;
/// <summary>
/// Checks which usernames, passwords, and access tokens of ERI data sources AI Studio accepts, and
/// what it tells the user about the others.
/// </summary>
/// <remarks>
/// <para>
/// ERI v1 sends all three in HTTP headers, which carry nothing but ASCII. An access token is checked
/// like an API key; a password and a username may contain spaces, since people choose them.
/// </para>
/// <para>
/// The invisible characters are built from their code points, so that nobody has to trust an
/// editor to keep characters it does not show. Nothing here asserts on the wording of a message:
/// I18N is process-wide state without a reset. Whether a message names a character shows instead
/// in whether two values with different characters get different messages.
/// </para>
/// </remarks>
[TestFixture]
public sealed class ERICredentialValidationTests
{
private const string DATA_SOURCE_NAME = "Project archive";
// A part of each secret which no message could contain by chance, whatever its language:
private const string SECRET_PART = "Xq7";
private static readonly string ZERO_WIDTH_SPACE = ((char)0x200B).ToString();
private static readonly string COMBINING_DIAERESIS = ((char)0x0308).ToString();
private static IEnumerable<string> CharactersBeyondAscii() =>
[
"ä", "ö", "ü", "Ä", "Ö", "Ü", "ß", "ẞ", "§", "°", "´", "µ", "²", "³", "€", "„", "“", "‚", "‘", "–", "…",
"é", "ø", "ş", "ł", "ж", "日本", "한",
$"a{COMBINING_DIAERESIS}", $"U{COMBINING_DIAERESIS}",
];
[TestCase("eyJhbGciOiJIUzI1NiJ9.e30.Xq7-_~+/=")]
[TestCase("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")]
public void ATokenOfPrintableAsciiPasses(string token) => Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.TOKEN, token), Is.EqualTo(APIKeyIssue.NONE));
[Test]
public void ATokenIsCheckedLikeAnAPIKey()
{
string[] tokens = [$"{SECRET_PART} token", $"{SECRET_PART}{ZERO_WIDTH_SPACE}", $"{SECRET_PART}„", $"{SECRET_PART}a{COMBINING_DIAERESIS}", $" {SECRET_PART}\n"];
using (Assert.EnterMultipleScope())
{
foreach (var token in tokens)
Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.TOKEN, token), Is.EqualTo(APIKeyValidation.Check(token)));
Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.TOKEN, $"{SECRET_PART} token").Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE), "A token allows no spaces.");
}
}
[Test]
public void APasswordMayContainSpaces()
{
using (Assert.EnterMultipleScope())
{
Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.USERNAME_PASSWORD, "Mein geheimes Passwort 2024!"), Is.EqualTo(APIKeyIssue.NONE));
Assert.That(ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, "Mein geheimes Passwort 2024!"), Is.Null);
}
}
[Test]
public void TheWhitespaceAroundAPasswordGoes()
{
using (Assert.EnterMultipleScope())
{
Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.USERNAME_PASSWORD, " Passwort\n"), Is.EqualTo(APIKeyIssue.NONE));
Assert.That(ERICredentialValidation.Normalize(" Passwort\n"), Is.EqualTo("Passwort"));
}
}
[TestCaseSource(nameof(CharactersBeyondAscii))]
public void ACharacterBeyondAsciiInAPasswordIsReported(string character) => Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.USERNAME_PASSWORD, $"Pass{character}wort 2024").Kind, Is.EqualTo(APIKeyIssueKind.NON_ASCII_CHARACTER));
[TestCase(0x0009)]
[TestCase(0x000A)]
[TestCase(0x000D)]
[TestCase(0x00A0)]
[TestCase(0x3000)]
public void OtherWhitespaceInAPasswordIsReported(int codePoint) => Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.USERNAME_PASSWORD, $"Pass{(char)codePoint}wort").Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE));
[TestCase(0x200B)]
[TestCase(0xFEFF)]
[TestCase(0x00AD)]
public void AnInvisibleCharacterInAPasswordIsReported(int codePoint) => Assert.That(ERICredentialValidation.CheckSecret(AuthMethod.USERNAME_PASSWORD, $"Pass{(char)codePoint}wort").Kind, Is.EqualTo(APIKeyIssueKind.INVISIBLE_CHARACTER));
[Test]
public void AMessageAboutAPasswordNamesNeitherTheCharacterNorThePassword()
{
var umlaut = ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, $"Grüße-{SECRET_PART}");
var decomposedUmlaut = ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, $"Gru{COMBINING_DIAERESIS}ße-{SECRET_PART}");
var euro = ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, $"Preis€-{SECRET_PART}");
var tab = ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, $"Pass\t{SECRET_PART}");
var invisible = ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, $"Pass{ZERO_WIDTH_SPACE}{SECRET_PART}");
using (Assert.EnterMultipleScope())
{
Assert.That(umlaut, Is.Not.Null.And.Not.Empty);
Assert.That(decomposedUmlaut, Is.EqualTo(umlaut), "The message must not depend on the character.");
Assert.That(euro, Is.EqualTo(umlaut), "The message must not depend on the character.");
Assert.That(tab, Is.Not.Null.And.Not.Empty);
Assert.That(invisible, Is.EqualTo(tab), "Whitespace and invisible characters share one message.");
foreach (var message in new[] { umlaut, tab })
Assert.That(message, Does.Not.Contain(SECRET_PART));
}
}
[Test]
public void AMessageAboutATokenNamesTheCharacterButNeverTheToken()
{
var lowQuotationMark = ERICredentialValidation.ValidateSecret(AuthMethod.TOKEN, $"{SECRET_PART}„token");
var highQuotationMark = ERICredentialValidation.ValidateSecret(AuthMethod.TOKEN, $"{SECRET_PART}“token");
using (Assert.EnterMultipleScope())
{
Assert.That(lowQuotationMark, Does.Contain("„"));
Assert.That(highQuotationMark, Is.Not.EqualTo(lowQuotationMark));
foreach (var token in new[] { $"{SECRET_PART} token", $"{SECRET_PART}{ZERO_WIDTH_SPACE}token", $"{SECRET_PART}„token" })
{
var message = ERICredentialValidation.ValidateSecret(AuthMethod.TOKEN, token);
Assert.That(message, Is.Not.Null.And.Not.Empty);
Assert.That(message, Does.Not.Contain(SECRET_PART));
}
}
}
[Test]
public void AUsernameMayContainSpaces()
{
using (Assert.EnterMultipleScope())
{
Assert.That(ERICredentialValidation.CheckUsername("Max Mustermann"), Is.EqualTo(APIKeyIssue.NONE));
Assert.That(ERICredentialValidation.ValidateUsername("Max Mustermann"), Is.Null);
Assert.That(ERICredentialValidation.CheckUsername("Max\tMustermann").Kind, Is.EqualTo(APIKeyIssueKind.WHITESPACE));
}
}
[Test]
public void AMessageAboutAUsernameNamesTheCharacter()
{
var composed = ERICredentialValidation.ValidateUsername("jürgen");
var decomposed = ERICredentialValidation.ValidateUsername($"ju{COMBINING_DIAERESIS}rgen");
var otherUmlaut = ERICredentialValidation.ValidateUsername("jörgen");
using (Assert.EnterMultipleScope())
{
Assert.That(ERICredentialValidation.CheckUsername($"ju{COMBINING_DIAERESIS}rgen"), Is.EqualTo(new APIKeyIssue(APIKeyIssueKind.NON_ASCII_CHARACTER, "ü")));
Assert.That(composed, Is.Not.Null.And.Not.Empty);
Assert.That(decomposed, Is.EqualTo(composed), "A decomposed umlaut is named as the one character the user sees.");
Assert.That(otherUmlaut, Is.Not.EqualTo(composed));
}
}
[Test]
public void EveryIssueHasAMessage()
{
string[] values = [$"a b{ZERO_WIDTH_SPACE}", $"a{ZERO_WIDTH_SPACE}", "a„", "a\tb"];
using (Assert.EnterMultipleScope())
{
foreach (var value in values)
{
Assert.That(ERICredentialValidation.ValidateSecret(AuthMethod.TOKEN, value), Is.Not.Null.And.Not.Empty, $"The token '{value}' has no message.");
Assert.That(ERICredentialValidation.ValidateUsername(value), Is.Not.Null.And.Not.Empty, $"The username '{value}' has no message.");
Assert.That(ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, value), Is.Not.Null.And.Not.Empty, $"The password '{value}' has no message.");
}
}
}
[Test]
public void AStoredValueIsNamedByItsDataSourceOnly()
{
var token = ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.TOKEN, DATA_SOURCE_NAME);
var password = ERICredentialValidation.GetUnusableSecretMessage(AuthMethod.USERNAME_PASSWORD, DATA_SOURCE_NAME);
var username = ERICredentialValidation.GetUnusableUsernameMessage(DATA_SOURCE_NAME);
using (Assert.EnterMultipleScope())
{
foreach (var message in new[] { token, password, username })
Assert.That(message, Does.Contain(DATA_SOURCE_NAME));
Assert.That(new[] { token, password, username }, Is.Unique, "Each value needs its own message.");
}
}
[TestCase(AuthMethod.NONE)]
[TestCase(AuthMethod.KERBEROS)]
public void WithoutASecretNothingIsChecked(AuthMethod authMethod)
{
using (Assert.EnterMultipleScope())
{
Assert.That(ERICredentialValidation.CheckSecret(authMethod, $"a{ZERO_WIDTH_SPACE}„"), Is.EqualTo(APIKeyIssue.NONE));
Assert.That(ERICredentialValidation.ValidateSecret(authMethod, $"a{ZERO_WIDTH_SPACE}„"), Is.Null);
}
}
[TestCase(null)]
[TestCase("")]
[TestCase(" \n")]
public void AMissingValueIsUpToTheCaller(string? value)
{
using (Assert.EnterMultipleScope())
{
Assert.That(ERICredentialValidation.ValidateSecret(AuthMethod.TOKEN, value), Is.Null);
Assert.That(ERICredentialValidation.ValidateSecret(AuthMethod.USERNAME_PASSWORD, value), Is.Null);
Assert.That(ERICredentialValidation.ValidateUsername(value), Is.Null);
}
}
}