[Server] Local environment updates overwrite immutable metadata
Description
Updating an environment through the local provider overwrites immutable/server-owned metadata. In addition to accepting a different organization, it resets createdAt to the update time and replaces the existing owner with the nil UUID.
Current Behavior
After updating only the environment name/description, the stored row has the payload's organization ID, a new creation timestamp, and a zero owner rather than the original values.
Expected Behavior
The REST contract states that an environment's organization cannot be changed after creation. createdAt and owner are response/server-owned fields and should also remain unchanged during a payload update.
Steps to Reproduce
- Persist an environment with known
organizationId,createdAt, andowner. - Call
DefaultLocalProvider.UpdateEnvironmentfor that ID with a payload containing a different organization. - Reload the row.
- Observe all three metadata fields were overwritten.
Evidence
$ go test ./server/models -run '^TestReproLocalEnvironmentUpdatePreservesImmutableFields$' -count=1
organization changed from <original-org> to <payload-org>
createdAt changed from <original-time> to <update-time>
owner changed from <owner-id> to 00000000-0000-0000-0000-000000000000
FAILRoot Cause
DefaultLocalProvider.UpdateEnvironment constructs a brand-new Environment from the update payload, setting CreatedAt: time.Now(), taking OrganizationID from the payload, and setting Owner to the nil UUID. It does not load and preserve the stored entity's immutable fields.
Affected Components
- Meshery Server
- Local provider
- Environment persistence/API contract
Validation
Executed on master commit 5b75615243e92b088b4ebf6e7bff82d6f60e5462:
go test ./server/models -run '^TestReproLocalEnvironmentUpdatePreservesImmutableFields$' -count=1Result: deterministic failure; organization, creation time, and owner all change.
Acceptance Criteria
- Updating an environment preserves its original organization, creation timestamp, and owner.
- Only mutable payload fields are changed.
- A regression test covers attempted organization changes and server-owned metadata.
References
Source: meshery/meshery