2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-13 10:45:29 +00:00

Token auth (#434)

* Embed device platform information into token request

* Remove username and password from userProfile

* Display icon to show if profile has associated user token

* Remove username / password from login settings screen

* Refactor login procedure around token auth

* Refactoring

* Add profile login screen

- Username / password values are not stored
- Just to fetch api token

* Login with basic auth

* Pass profile to API when connecting

* Remove _BASE_URL accessor

- Fixes URL caching bug

* Add more context to login screen

* Add helper functions for unit tests

- Change default port to 8000 (makes testing easier with local inventree instance)

* api.dart handles basic auth now

* fix api_test.dart

* Further test improvements

* linting fixes

* Provide feedback when login fails

* More linting

* Record user details on login, and display in "about" widget

* Fix string lookup

* Add extra debug

* Fix auth values

* Fix user profile test
This commit is contained in:
Oliver
2023-10-23 01:29:16 +11:00
committed by GitHub
parent 382c8461f9
commit 76b6191a67
18 changed files with 1023 additions and 705 deletions

View File

@ -27,10 +27,8 @@ void main() {
// Now, create one!
bool result = await UserProfileDBManager().addProfile(UserProfile(
name: "Test Profile",
username: "testuser",
password: "testpassword""",
server: "http://localhost:12345",
name: testServerName,
server: testServerAddress,
selected: true,
));
@ -62,20 +60,15 @@ void main() {
test("Add Invalid Profiles", () async {
// Add a profile with missing data
bool result = await UserProfileDBManager().addProfile(
UserProfile(
username: "what",
password: "why",
)
UserProfile()
);
expect(result, equals(false));
// Add a profile with a name that already exists
// Add a profile with a new name
result = await UserProfileDBManager().addProfile(
UserProfile(
name: "Test Profile",
username: "xyz",
password: "hunter42",
name: "Another Test Profile",
)
);
@ -84,14 +77,14 @@ void main() {
// Check that the number of protocols available is still the same
var profiles = await UserProfileDBManager().getAllProfiles();
expect(profiles.length, equals(1));
expect(profiles.length, equals(2));
});
test("Profile Name Check", () async {
bool result = await UserProfileDBManager().profileNameExists("doesnotexist");
expect(result, equals(false));
result = await UserProfileDBManager().profileNameExists("Test Profile");
result = await UserProfileDBManager().profileNameExists("Test Server");
expect(result, equals(true));
});
@ -104,23 +97,16 @@ void main() {
if (prf != null) {
UserProfile p = prf;
expect(p.name, equals("Test Profile"));
expect(p.username, equals("testuser"));
expect(p.password, equals("testpassword"));
expect(p.server, equals("http://localhost:12345"));
expect(p.name, equals(testServerName));
expect(p.server, equals(testServerAddress));
expect(p.toString(), equals("<${p.key}> Test Profile : http://localhost:12345 - testuser:testpassword"));
expect(p.toString(), equals("<${p.key}> Test Server : http://localhost:8000/"));
// Test that we can update the profile
p.name = "different name";
bool result = await UserProfileDBManager().updateProfile(p);
expect(result, equals(true));
// Trying to update with an invalid value will fail!
p.password = "";
result = await UserProfileDBManager().updateProfile(p);
expect(result, equals(false));
}
});
});