feat(World API): show Hypergrid friends and permission-gated last online in minutes/hours (#341)
* feat(world-api): safely parse Hypergrid friend UUI and format accurate last-logout activity * feat(world-api): list confirmed HG friend identities and permission-gated local last-online intervals * feat(world-api): reuse existing ROBUST GridUserService for reliable friend logout timestamps * test(world-api): executable HG friend UUI and accurate last-online duration regressions * test(world-api): executable HG friend UUI and accurate last-online duration regressions * docs(world-api): document Hypergrid friends and permission-gated local last-online minutes/hours * test(world-api): verify HG friend projection, permission guards and timestamp data provenance * ci(world-api): test Hypergrid UUI, rights and accurate last-online minutes/hours * fix(world-api): distinguish unavailable presence and permit local-grid HG visit timestamps via exact UUI * docs/test(world-api): make local HG visit visibility and unknown remote status explicit * docs/test(world-api): make local HG visit visibility and unknown remote status explicit * fix(world-api): reject over-delimited HG UUI without reading federation secret
This commit is contained in:
1 parent
b40d8713d1
commit
6f3ae64196
8 files changed
+470
-18
No files matched your search
@@ -457,6 +457,13 @@ jobs:
|
||||
bash addon-modules/NexSmartLight/build.sh Release
|
||||
|
||||
|
||||
- name: Regression-test World API Hypergrid friends and last online
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
python3 tools/ci/verify_worldapi_hg_friend_activity.py
|
||||
dotnet run --configuration Release --project tools/ci/NexRelationshipPresenceRegression/NexRelationshipPresenceRegression.csproj
|
||||
|
||||
- name: Verify citizen social and profile integration
|
||||
shell: bash
|
||||
run: python3 tools/ci/verify_citizen_social_profile.py
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
using System;
|
||||
|
||||
namespace NexVerse.Server.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Value-only projection for local UUID and Hypergrid UUI friend keys.
|
||||
/// HG friend records may contain a federation secret after the third
|
||||
/// semicolon; NEVER return it through an HTTP endpoint.
|
||||
/// </summary>
|
||||
internal static class NexRelationshipPresenceModel
|
||||
{
|
||||
internal sealed class Identity
|
||||
{
|
||||
public Guid Id;
|
||||
public bool IsHypergrid;
|
||||
public string HomeGrid;
|
||||
public string ForeignName;
|
||||
}
|
||||
|
||||
internal sealed class Activity
|
||||
{
|
||||
public string LastOnlineAtUtc;
|
||||
public long? LastOnlineMinutes;
|
||||
public long? LastOnlineHours;
|
||||
public string LastOnlineLabel;
|
||||
}
|
||||
|
||||
internal static bool TryParseIdentity(string friendKey, out Identity identity)
|
||||
{
|
||||
identity = null;
|
||||
if (string.IsNullOrWhiteSpace(friendKey))
|
||||
return false;
|
||||
string value = friendKey.Trim();
|
||||
if (value.Length == 36 &&
|
||||
Guid.TryParseExact(value, "D", out Guid localId) &&
|
||||
localId != Guid.Empty)
|
||||
{
|
||||
identity = new Identity
|
||||
{
|
||||
Id = localId,
|
||||
IsHypergrid = false,
|
||||
HomeGrid = null,
|
||||
ForeignName = string.Empty
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
// Standard OpenSim UUI: UUID;homeGridURI;First Last[;secret].
|
||||
// Split at most four fields and discard the fourth immediately.
|
||||
// Require the UUID segment to be exactly 36 chars.
|
||||
int separators = 0;
|
||||
foreach (char ch in value)
|
||||
if (ch == ';') separators++;
|
||||
if (separators < 2 || separators > 3)
|
||||
return false;
|
||||
string[] parts = value.Split(';', 4);
|
||||
if ((parts.Length != 3 && parts.Length != 4) ||
|
||||
!Guid.TryParseExact(parts[0], "D", out Guid foreignId) ||
|
||||
foreignId == Guid.Empty ||
|
||||
parts[1].Length == 0 || parts[1].Length > 512 ||
|
||||
!Uri.TryCreate(parts[1], UriKind.Absolute, out Uri home) ||
|
||||
(home.Scheme != Uri.UriSchemeHttp &&
|
||||
home.Scheme != Uri.UriSchemeHttps) ||
|
||||
!string.IsNullOrEmpty(home.UserInfo) ||
|
||||
string.IsNullOrWhiteSpace(parts[2]) ||
|
||||
parts[2].Length > 128)
|
||||
return false;
|
||||
|
||||
identity = new Identity
|
||||
{
|
||||
Id = foreignId,
|
||||
IsHypergrid = true,
|
||||
// Keep the normalized grid URI, no URL query, fragments,
|
||||
// credentials or UUI federation secret.
|
||||
HomeGrid = home.GetLeftPart(UriPartial.Path).TrimEnd('/'),
|
||||
ForeignName = parts[2].Trim()
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Last online" is based ONLY on a real logout stored in the
|
||||
/// local GridUser service. Online and remote-grid activity must not
|
||||
/// be inferred from older logouts or last-login values.
|
||||
/// </summary>
|
||||
internal static Activity LastLogout(
|
||||
DateTime logout, DateTimeOffset now, bool authorized, bool online)
|
||||
{
|
||||
var result = new Activity();
|
||||
if (!authorized || online || logout == default)
|
||||
return result;
|
||||
|
||||
DateTime utc = logout.Kind == DateTimeKind.Unspecified
|
||||
? DateTime.SpecifyKind(logout, DateTimeKind.Utc)
|
||||
: logout.ToUniversalTime();
|
||||
var stamp = new DateTimeOffset(utc);
|
||||
if (stamp <= DateTimeOffset.FromUnixTimeSeconds(0) ||
|
||||
stamp > now)
|
||||
return result;
|
||||
|
||||
long minutes = (long)Math.Max(
|
||||
0, Math.Floor((now - stamp).TotalMinutes));
|
||||
result.LastOnlineAtUtc = stamp.ToString("yyyy-MM-ddTHH:mm:ssZ",
|
||||
System.Globalization.CultureInfo.InvariantCulture);
|
||||
result.LastOnlineMinutes = minutes;
|
||||
result.LastOnlineHours = minutes / 60;
|
||||
if (minutes < 1)
|
||||
result.LastOnlineLabel = "gerade eben";
|
||||
else if (minutes < 60)
|
||||
result.LastOnlineLabel = "vor " + minutes +
|
||||
(minutes == 1 ? " Minute" : " Minuten");
|
||||
else if (minutes < 1440)
|
||||
{
|
||||
long hours = minutes / 60;
|
||||
result.LastOnlineLabel = "vor " + hours +
|
||||
(hours == 1 ? " Stunde" : " Stunden");
|
||||
}
|
||||
else
|
||||
{
|
||||
long days = minutes / 1440;
|
||||
result.LastOnlineLabel = "vor " + days +
|
||||
(days == 1 ? " Tag" : " Tagen");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,9 @@ namespace NexVerse.Server.Api
|
||||
private readonly IMuteListService m_Mutes;
|
||||
private readonly INexAuditSink m_Audit;
|
||||
private readonly IPresenceService m_Presence;
|
||||
private readonly IGridUserService m_GridUsers;
|
||||
|
||||
public NexSocialGraphApi(IUserAccountService accounts, IFriendsService friends, NexApiAuthenticator auth, IMuteListService mutes, INexAuditSink audit, IPresenceService presence)
|
||||
public NexSocialGraphApi(IUserAccountService accounts, IFriendsService friends, NexApiAuthenticator auth, IMuteListService mutes, INexAuditSink audit, IPresenceService presence, IGridUserService gridUsers = null)
|
||||
{
|
||||
m_Accounts = accounts ?? throw new ArgumentNullException(nameof(accounts));
|
||||
m_Friends = friends ?? throw new ArgumentNullException(nameof(friends));
|
||||
@@ -33,6 +34,7 @@ namespace NexVerse.Server.Api
|
||||
m_Mutes = mutes ?? throw new ArgumentNullException(nameof(mutes));
|
||||
m_Audit = audit ?? NullNexAuditSink.Instance;
|
||||
m_Presence = presence;
|
||||
m_GridUsers = gridUsers;
|
||||
}
|
||||
|
||||
public void Handle(IOSHttpRequest request, IOSHttpResponse response)
|
||||
@@ -65,7 +67,9 @@ namespace NexVerse.Server.Api
|
||||
Write(response, HttpStatusCode.OK, new
|
||||
{
|
||||
principal_id = owner.ToString(),
|
||||
relationships = friends.Select(Project).ToArray()
|
||||
relationships = friends.Where(f =>
|
||||
f != null && NexRelationshipPresenceModel.TryParseIdentity(
|
||||
f.Friend, out _)).Select(Project).ToArray()
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -228,30 +232,103 @@ namespace NexVerse.Server.Api
|
||||
|
||||
private object Project(FriendInfo f)
|
||||
{
|
||||
UUID.TryParse(f.Friend, out UUID id);
|
||||
UserAccount account = id.IsZero() ? null : m_Accounts.GetUserAccount(UUID.Zero, id);
|
||||
// GetFriends(UUID) returns the authoritative FULL Friend string:
|
||||
// local UUID, or HG UUI "uuid;homeUri;First Last;secret".
|
||||
// Never expose the secret, and never mistake a remote UUID
|
||||
// for a locally registered account with the same numeric ID.
|
||||
NexRelationshipPresenceModel.TryParseIdentity(
|
||||
f.Friend, out NexRelationshipPresenceModel.Identity identity);
|
||||
UUID id = new UUID(identity.Id.ToString());
|
||||
|
||||
UserAccount account = identity.IsHypergrid
|
||||
? null : m_Accounts.GetUserAccount(UUID.Zero, id);
|
||||
bool confirmed = f.MyFlags >= 0 && f.TheirFlags >= 0;
|
||||
// TheirFlags describe what THIS friend permits the owner to see.
|
||||
bool canSeeOnline = confirmed && (f.TheirFlags & 1) != 0;
|
||||
bool online = false;
|
||||
bool presenceKnown = canSeeOnline &&
|
||||
TryGetOnline(id, out online);
|
||||
|
||||
// Local GridUser.Logout is authoritative only for activity on
|
||||
// THIS grid. With a HG user the key must remain the full UUI,
|
||||
// never the bare UUID (which could name a local avatar).
|
||||
// No request to the foreign home grid is performed.
|
||||
NexRelationshipPresenceModel.Activity activity =
|
||||
new NexRelationshipPresenceModel.Activity();
|
||||
if (canSeeOnline && presenceKnown && !online &&
|
||||
m_GridUsers != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
GridUserInfo gridUser =
|
||||
m_GridUsers.GetGridUserInfo(
|
||||
identity.IsHypergrid ? f.Friend : id.ToString());
|
||||
if (gridUser != null)
|
||||
activity = NexRelationshipPresenceModel.LastLogout(
|
||||
gridUser.Logout, DateTimeOffset.UtcNow, true, false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Optional GridUser backend unavailable: do not turn the
|
||||
// entire private friend list into a 500 or fabricate time.
|
||||
}
|
||||
}
|
||||
|
||||
string username = account?.Username ??
|
||||
(identity.IsHypergrid ? identity.ForeignName : string.Empty);
|
||||
string display = account?.EffectiveDisplayName ??
|
||||
(identity.IsHypergrid ? identity.ForeignName : string.Empty);
|
||||
return new
|
||||
{
|
||||
principal_id = id.ToString(),
|
||||
username = account?.Username ?? string.Empty,
|
||||
display_name = account?.EffectiveDisplayName ?? string.Empty,
|
||||
state = f.TheirFlags == -1 ? "incoming_pending" : (f.MyFlags == -1 ? "outgoing_pending" : "friends"),
|
||||
username,
|
||||
display_name = display,
|
||||
is_hypergrid = identity.IsHypergrid,
|
||||
home_grid = identity.HomeGrid,
|
||||
state = f.TheirFlags == -1 ? "incoming_pending" :
|
||||
(f.MyFlags == -1 ? "outgoing_pending" : "friends"),
|
||||
rights = f.MyFlags,
|
||||
their_rights = f.TheirFlags,
|
||||
// TheirFlags describe what the friend grants this avatar.
|
||||
can_see_online = f.MyFlags >= 0 && f.TheirFlags >= 0 && (f.TheirFlags & 1) != 0,
|
||||
online = f.MyFlags >= 0 && f.TheirFlags >= 0 && (f.TheirFlags & 1) != 0 && IsOnline(id),
|
||||
can_see_on_map = f.MyFlags >= 0 && f.TheirFlags >= 0 && (f.TheirFlags & 2) != 0,
|
||||
can_modify_objects = f.MyFlags >= 0 && f.TheirFlags >= 0 && (f.TheirFlags & 4) != 0
|
||||
can_see_online = canSeeOnline,
|
||||
// Backward compatible bool: presence on THIS grid only.
|
||||
// For a foreign HG friend false does NOT mean globally offline.
|
||||
online,
|
||||
online_status = !presenceKnown
|
||||
? "unknown"
|
||||
: online ? "online" :
|
||||
identity.IsHypergrid ? "unknown" : "offline",
|
||||
online_scope = "local_grid",
|
||||
can_see_on_map = confirmed && (f.TheirFlags & 2) != 0,
|
||||
can_modify_objects = confirmed && (f.TheirFlags & 4) != 0,
|
||||
last_online_at_utc = activity.LastOnlineAtUtc,
|
||||
last_online_minutes = activity.LastOnlineMinutes,
|
||||
last_online_hours = activity.LastOnlineHours,
|
||||
last_online_label = activity.LastOnlineLabel,
|
||||
last_online_scope = activity.LastOnlineAtUtc == null
|
||||
? "unknown" : "local_grid_logout"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private bool IsOnline(UUID id)
|
||||
private bool TryGetOnline(UUID id, out bool online)
|
||||
{
|
||||
if (m_Presence == null || id.IsZero()) return false;
|
||||
PresenceInfo[] presences = m_Presence.GetAgents(new[] { id.ToString() });
|
||||
return presences != null && presences.Any(x => x != null && !x.RegionID.IsZero());
|
||||
online = false;
|
||||
if (m_Presence == null || id.IsZero())
|
||||
return false;
|
||||
try
|
||||
{
|
||||
PresenceInfo[] presences =
|
||||
m_Presence.GetAgents(new[] { id.ToString() });
|
||||
if (presences == null)
|
||||
return false;
|
||||
online = presences.Any(
|
||||
x => x != null && !x.RegionID.IsZero());
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Unavailable presence must report UNKNOWN, not "offline".
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool Authenticate(IOSHttpRequest request, IOSHttpResponse response, string scope, out NexPrincipal principal)
|
||||
|
||||
@@ -1099,7 +1099,7 @@ namespace NexVerse.Server.Api
|
||||
|
||||
FriendsService friendsService = new FriendsService(config);
|
||||
NexSocialGraphApi socialGraph =
|
||||
new NexSocialGraphApi(userAccounts, friendsService, authenticator, new MuteListService(config), auditSink, presence);
|
||||
new NexSocialGraphApi(userAccounts, friendsService, authenticator, new MuteListService(config), auditSink, presence, gridUsers);
|
||||
server.AddSimpleStreamHandler(
|
||||
new SimpleStreamHandler(
|
||||
"/api/v1/relationships",
|
||||
|
||||
@@ -20,6 +20,78 @@ und die World API verwenden.
|
||||
- `PUT /api/v1/relationships/{principalId}/blocks/{friendId}` —
|
||||
blockiert Avatar und beendet Freundschaft.
|
||||
|
||||
### Hypergrid-Freunde und „zuletzt online“
|
||||
|
||||
`GET /api/v1/relationships/{principalId}` liefert jetzt **lokale und
|
||||
Hypergrid-Freunde aus derselben OpenSim-Friends-Datenbank**. OpenSim
|
||||
speichert externe Kontakte als Universal User Identifier
|
||||
`UUID;HomeGridURI;Vorname Nachname[;FriendshipSecret]`. Die API
|
||||
wertet diese Identität aus, zeigt den tatsächlichen HG-Namen und das
|
||||
Heimatgrid und **überträgt das FriendshipSecret niemals an den Client**.
|
||||
|
||||
Die bisherigen Felder `principal_id`, `username`, `display_name`,
|
||||
`state`, `rights`, `their_rights`, `can_see_online`, `online`,
|
||||
`can_see_on_map` und `can_modify_objects` bleiben erhalten.
|
||||
Zusätzlich pro Eintrag:
|
||||
|
||||
| Feld | Bedeutung |
|
||||
| --- | --- |
|
||||
| `is_hypergrid` | `true` bei gespeichertem fremden UUI |
|
||||
| `home_grid` | Heimatgrid-URL oder `null` bei lokalem Avatar |
|
||||
| `online_status` | `online`, `offline` oder `unknown` |
|
||||
| `online_scope` | Aktuell immer `local_grid` |
|
||||
| `last_online_at_utc` | Tatsächlich gespeicherter letzter Logout als UTC-ISO8601, sonst `null` |
|
||||
| `last_online_minutes` | Ganze Minuten seit diesem Logout, sonst `null` |
|
||||
| `last_online_hours` | Ganze Stunden seit diesem Logout, sonst `null` |
|
||||
| `last_online_label` | UI-Text, etwa `vor 12 Minuten` oder `vor 3 Stunden` |
|
||||
| `last_online_scope` | `local_grid_logout` (nur hier zuletzt gesehen), sonst `unknown` |
|
||||
|
||||
Beispiel für einen **lokalen**, berechtigten Offline-Freund:
|
||||
|
||||
```json
|
||||
{
|
||||
"principal_id": "11111111-1111-4111-8111-111111111111",
|
||||
"username": "Beispiel Avatar",
|
||||
"is_hypergrid": false,
|
||||
"home_grid": null,
|
||||
"can_see_online": true,
|
||||
"online": false,
|
||||
"online_status": "offline",
|
||||
"online_scope": "local_grid",
|
||||
"last_online_at_utc": "2026-10-28T18:00:00Z",
|
||||
"last_online_minutes": 125,
|
||||
"last_online_hours": 2,
|
||||
"last_online_label": "vor 2 Stunden",
|
||||
"last_online_scope": "local_grid_logout"
|
||||
}
|
||||
```
|
||||
|
||||
Die Zeitangaben sind Beispielwerte, **nicht** die echte Datenbankzeit des
|
||||
oben genannten Avatarbeispiels. Zum Rendern einer dynamischen Freundesliste
|
||||
die Minuten/Stunden anhand `last_online_at_utc` im Portal laufend
|
||||
aktualisieren; der API-Response ist eine Momentaufnahme.
|
||||
|
||||
**Privatsphäre und technische Grenze:** Nur bestätigte Freundschaften
|
||||
mit durch `TheirFlags & 1` eingeräumtem Online-Sichtrecht dürfen einen
|
||||
Online-Status bzw. Logout-Zeitpunkt erhalten. Pending-Freundschaften
|
||||
und entzogene Sichtrechte liefern `null` bei allen „zuletzt online“-Feldern.
|
||||
`GridUser.Logout` ist der letzte **lokal** dokumentierte Logout.
|
||||
Bei Hypergrid-Freunden sind Login-/Logout-Zeitpunkte auf
|
||||
**anderen Grids** nicht zuverlässig verfügbar. Wenn der Gast dagegen
|
||||
**unser Grid besucht** hat, kann ein hier gespeicherter letzter Logout
|
||||
unter seinem exakten UUI angezeigt werden (`last_online_scope =
|
||||
local_grid_logout`). Fehlt eine solche lokale Aufzeichnung, bleiben
|
||||
die `last_online_*`-Felder `null`. `online_status` ist bei auswärtigen
|
||||
Freunden außerhalb einer beobachteten aktiven Präsenz `unknown`.
|
||||
Das bisherige boolesche `online=false` darf bei HG-Freunden **nicht**
|
||||
als „weltweit offline“ interpretiert werden. Diese Version startet
|
||||
keine HTTP-Abfragen an beliebige externe Heimatsysteme und speichert
|
||||
keine zusätzlichen privaten Verlaufsdaten.
|
||||
|
||||
Der Avatarbesitzer wird weiterhin über OAuth und `relationships:read`
|
||||
authentifiziert, die Ownerprüfung bleibt bestehen; die REST-Ausgabe
|
||||
wird mit `Cache-Control: no-store` geliefert.
|
||||
|
||||
Der API-Scope ist `relationships:read` bzw. `relationships:write`.
|
||||
**Ownerprüfung gilt zusätzlich**. Der Online-Status eines Freundes
|
||||
wird nur gezeigt, soweit dieser die notwendigen Viewer-Freundesrechte
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="../../../NexVerse/Server/Api/NexRelationshipPresenceModel.cs"
|
||||
Link="NexRelationshipPresenceModel.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using NexVerse.Server.Api;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private static int s_Count;
|
||||
private static void Require(bool condition, string message)
|
||||
{
|
||||
s_Count++;
|
||||
if (!condition)
|
||||
throw new Exception("Relationship HG/last-online: " + message);
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
const string local = "11111111-1111-4111-8111-111111111111";
|
||||
const string foreign = "22222222-2222-4222-8222-222222222222";
|
||||
Require(NexRelationshipPresenceModel.TryParseIdentity(
|
||||
local, out var localFriend) &&
|
||||
!localFriend.IsHypergrid &&
|
||||
localFriend.HomeGrid == null &&
|
||||
localFriend.Id.ToString() == local,
|
||||
"plain UUID local friend");
|
||||
Require(NexRelationshipPresenceModel.TryParseIdentity(
|
||||
foreign + ";http://hg.example.net:8002;Antonia Porta",
|
||||
out var foreignFriend) &&
|
||||
foreignFriend.IsHypergrid &&
|
||||
foreignFriend.HomeGrid == "http://hg.example.net:8002" &&
|
||||
foreignFriend.ForeignName == "Antonia Porta" &&
|
||||
foreignFriend.Id.ToString() == foreign,
|
||||
"full HG UUI and display name");
|
||||
Require(NexRelationshipPresenceModel.TryParseIdentity(
|
||||
foreign + ";https://example.net/opensim/;Trixi Back;TOP-SECRET",
|
||||
out var secretFriend) &&
|
||||
secretFriend.IsHypergrid &&
|
||||
secretFriend.HomeGrid == "https://example.net/opensim" &&
|
||||
secretFriend.ForeignName == "Trixi Back" &&
|
||||
!secretFriend.HomeGrid.Contains("SECRET", StringComparison.Ordinal) &&
|
||||
!secretFriend.ForeignName.Contains("SECRET", StringComparison.Ordinal),
|
||||
"HG federation secret stripped from every projected field");
|
||||
foreach (string invalid in new[]
|
||||
{
|
||||
"", "not-a-uuid",
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
foreign + ";http://hg.example.net; ",
|
||||
foreign + ";javascript:alert(1);Tester Guest",
|
||||
foreign + ";https://user:pass@example.net;Tester Guest",
|
||||
foreign + ";http://hg.example.net;Tester Guest;secret;extra",
|
||||
"bad-id;http://grid.example;Tester Guest"
|
||||
})
|
||||
{
|
||||
Require(!NexRelationshipPresenceModel.TryParseIdentity(
|
||||
invalid, out _), "reject malformed/unsafe UUI " + invalid);
|
||||
}
|
||||
|
||||
DateTimeOffset now = new DateTimeOffset(
|
||||
2026, 10, 28, 21, 0, 0, TimeSpan.Zero);
|
||||
for (int minutes = 0; minutes < 61 * 24; minutes++)
|
||||
{
|
||||
DateTime logout = now.AddMinutes(-minutes).UtcDateTime;
|
||||
var a = NexRelationshipPresenceModel.LastLogout(
|
||||
logout, now, true, false);
|
||||
Require(a.LastOnlineMinutes == minutes,
|
||||
"accurate minute clock");
|
||||
Require(a.LastOnlineHours == minutes / 60,
|
||||
"accurate hour floor");
|
||||
Require(a.LastOnlineAtUtc != null && a.LastOnlineLabel != null,
|
||||
"valid logout yields timestamp and label");
|
||||
}
|
||||
Require(NexRelationshipPresenceModel.LastLogout(
|
||||
now.AddMinutes(-1).UtcDateTime, now, true, false)
|
||||
.LastOnlineLabel == "vor 1 Minute", "singular minute");
|
||||
Require(NexRelationshipPresenceModel.LastLogout(
|
||||
now.AddMinutes(-120).UtcDateTime, now, true, false)
|
||||
.LastOnlineLabel == "vor 2 Stunden", "plural hour");
|
||||
Require(NexRelationshipPresenceModel.LastLogout(
|
||||
now.AddDays(-1).UtcDateTime, now, true, false)
|
||||
.LastOnlineLabel == "vor 1 Tag", "singular day");
|
||||
foreach (DateTime date in new[]
|
||||
{
|
||||
default(DateTime), new DateTime(1970, 1, 1, 0, 0, 0,
|
||||
DateTimeKind.Utc),
|
||||
now.AddHours(1).UtcDateTime
|
||||
})
|
||||
Require(NexRelationshipPresenceModel.LastLogout(
|
||||
date, now, true, false).LastOnlineMinutes == null,
|
||||
"unknown/epoch/future date must remain null");
|
||||
Require(NexRelationshipPresenceModel.LastLogout(
|
||||
now.AddHours(-3).UtcDateTime, now, false, false)
|
||||
.LastOnlineMinutes == null, "friend without permission");
|
||||
Require(NexRelationshipPresenceModel.LastLogout(
|
||||
now.AddHours(-3).UtcDateTime, now, true, true)
|
||||
.LastOnlineMinutes == null, "online friend has no offline age");
|
||||
|
||||
Console.WriteLine("Nex Relationship HG and last-online: " +
|
||||
s_Count + " checks PASS");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fail-closed source contract for private World API friend activity.
|
||||
|
||||
Runnable C# model test covers parsing and elapsed-time edge cases.
|
||||
Source checks tie it to the authenticated REST route and backend.
|
||||
"""
|
||||
from pathlib import Path
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
def read(path):
|
||||
return (ROOT / path).read_text(encoding="utf-8-sig")
|
||||
|
||||
api = read("NexVerse/Server/Api/NexSocialGraphApi.cs")
|
||||
model = read("NexVerse/Server/Api/NexRelationshipPresenceModel.cs")
|
||||
connector = read("NexVerse/Server/Api/NexVerseWorldApiConnector.cs")
|
||||
docs = read("doc/NexVerse/PORTAL_SOCIAL_PROFILE.md")
|
||||
tests = read("tools/ci/NexRelationshipPresenceRegression/Program.cs")
|
||||
workflow = read(".github/workflows/nexjast-ci.yml")
|
||||
assert '"GET", StringComparison.OrdinalIgnoreCase)' in api
|
||||
assert "NexScopes.RelationshipsRead" in api
|
||||
assert "if (!Owns(principal, owner))" in api
|
||||
assert "m_Friends.GetFriends(owner)" in api
|
||||
assert "NexRelationshipPresenceModel.TryParseIdentity(" in api
|
||||
assert "m_GridUsers.GetGridUserInfo(" in api
|
||||
assert "identity.IsHypergrid ? identity.ForeignName" in api
|
||||
assert "identity.IsHypergrid" in api
|
||||
assert "canSeeOnline = confirmed && (f.TheirFlags & 1) != 0" in api
|
||||
assert "canSeeOnline && presenceKnown && !online" in api
|
||||
assert "identity.IsHypergrid ? f.Friend : id.ToString()" in api
|
||||
assert "TryGetOnline(UUID id, out bool online)" in api
|
||||
assert 'last_online_scope = activity.LastOnlineAtUtc == null' in api
|
||||
for field in (
|
||||
"is_hypergrid", "home_grid", "online_status", "online_scope",
|
||||
"last_online_at_utc", "last_online_minutes", "last_online_hours",
|
||||
"last_online_label", "last_online_scope",
|
||||
):
|
||||
assert field in api and field in docs, field
|
||||
assert '"local_grid"' in api and '"unknown"' in api
|
||||
assert '"local_grid_logout"' in api
|
||||
assert "Cache-Control" in api and "no-store" in api
|
||||
assert "response.RawBuffer = Encoding.UTF8.GetBytes" in api
|
||||
assert "m_Accounts.GetUserAccount(UUID.Zero, id)" in api
|
||||
assert "new NexSocialGraphApi(userAccounts, friendsService, authenticator," in connector
|
||||
assert "auditSink, presence, gridUsers)" in connector
|
||||
assert "LoadOptionalService<IGridUserService>(config, \"GridUserService\")" in connector
|
||||
assert "value.Split(';', 4)" in model
|
||||
assert "Guid.TryParseExact" in model
|
||||
assert "home.UserInfo" in model
|
||||
assert "TrimEnd('/')" in model
|
||||
assert "parts[2].Trim()" in model
|
||||
assert "parts[3]" not in model, "HG federation secrets must never be read"
|
||||
assert "LastLogout(" in model
|
||||
assert "DateTimeOffset.FromUnixTimeSeconds(0)" in model
|
||||
assert "if (!authorized || online" in model
|
||||
assert "for (int minutes = 0; minutes < 61 * 24; minutes++)" in tests
|
||||
assert "HG federation secret" in tests
|
||||
assert "Regression-test World API Hypergrid friends and last online" in workflow
|
||||
assert "friends.Select(Project)" not in api, "unparsed HG UUI entries"
|
||||
print("World API HG friends and private last-online source contracts PASS")
|
||||
Reference in new issue
Block a user