如何用API键调用TestRail?
How to call TestRail with API Key?
我正在尝试将 NUnit 与 TestRail 集成。正在尝试创建测试 运行 并从给定的测试套件执行所需的测试用例。
能够实现整合。但挑战是如何传递 API Key?
到目前为止,我可以通过用户名和密码调用API。但是出于安全原因,我不想将用户名和密码暴露给其他人。
示例代码如下:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.ContentType = "application/json";
request.Method = method;
string auth = Convert.ToBase64String( Encoding.ASCII.GetBytes("{mUser}:mPassword}" ) );
request.Headers.Add("Authorization", "Basic " + auth);
但是我不确定,有没有办法传API密钥?
注意:我能够在 TestRail
中创建 API 键
从 TestRails 文档的外观来看,它似乎总是需要用户名和次要元素。次要元素是您的帐户密码或 API 密钥。
Username and API Key
Alternatively TestRail also supports API keys. API keys can be generated in TestRail
under My Settings. With an API key you would still use HTTP basic authentication and you
would still send your TestRail username (e.g. your email address). You would just
replace your password with any of the generated/active API keys. You can generate
multiple API keys for different systems or third-party tools and revoke access by
deleting the API key at any time under My Settings.
Source
从程序中混淆您的用户名意味着将这些详细信息放入您的 app.config 文件中。另一方面,如果您公开发布代码,则可能需要将其完全移出代码,否则开发人员会看到它。
至少要回答问题,传递你的 API 密钥,在你当前的代码中用它替换你的密码。
我正在尝试将 NUnit 与 TestRail 集成。正在尝试创建测试 运行 并从给定的测试套件执行所需的测试用例。
能够实现整合。但挑战是如何传递 API Key?
到目前为止,我可以通过用户名和密码调用API。但是出于安全原因,我不想将用户名和密码暴露给其他人。
示例代码如下:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.ContentType = "application/json";
request.Method = method;
string auth = Convert.ToBase64String( Encoding.ASCII.GetBytes("{mUser}:mPassword}" ) );
request.Headers.Add("Authorization", "Basic " + auth);
但是我不确定,有没有办法传API密钥?
注意:我能够在 TestRail
中创建 API 键从 TestRails 文档的外观来看,它似乎总是需要用户名和次要元素。次要元素是您的帐户密码或 API 密钥。
Username and API Key
Alternatively TestRail also supports API keys. API keys can be generated in TestRail under My Settings. With an API key you would still use HTTP basic authentication and you would still send your TestRail username (e.g. your email address). You would just replace your password with any of the generated/active API keys. You can generate multiple API keys for different systems or third-party tools and revoke access by deleting the API key at any time under My Settings. Source
从程序中混淆您的用户名意味着将这些详细信息放入您的 app.config 文件中。另一方面,如果您公开发布代码,则可能需要将其完全移出代码,否则开发人员会看到它。
至少要回答问题,传递你的 API 密钥,在你当前的代码中用它替换你的密码。