forked from line/centraldogma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare Token Updates for line#1054 Compatibility
Motivation To ensure smooth compatibility with line#1054, the `Token` structure needs an update to support changes in `admin` property. Modifications: - Enhanced the Token deserializer to accept both `admin` and `systemAdmin` properties, ensuring backward compatibility. - Updated `MetadataService.updateTokenLevel()` to avoid direct access to the `admin` property. Result: - The `Token` structure now supports the upcoming changes, allowing seamless updates with line#1054.
- Loading branch information
Showing
4 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
server/src/test/java/com/linecorp/centraldogma/server/metadata/TokenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linecorp.centraldogma.server.metadata; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.linecorp.centraldogma.internal.Jackson; | ||
|
||
class TokenTest { | ||
|
||
private static final String APP_ID = "foo-id"; | ||
private static final String APP_SECRET = "appToken-foo"; | ||
|
||
@Test | ||
void deserializeToken() throws Exception { | ||
final String legacyTokenJson = tokenJson(true); | ||
final Token legacyToken = Jackson.readValue(legacyTokenJson, Token.class); | ||
assertThat(legacyToken.appId()).isEqualTo(APP_ID); | ||
assertThat(legacyToken.isAdmin()).isTrue(); | ||
|
||
final String tokenJson = tokenJson(false); | ||
final Token token = Jackson.readValue(tokenJson, Token.class); | ||
assertThat(token.appId()).isEqualTo(APP_ID); | ||
assertThat(token.isAdmin()).isTrue(); | ||
} | ||
|
||
private static String tokenJson(boolean legacy) { | ||
return "{\"appId\": \"" + APP_ID + "\"," + | ||
" \"secret\": \"" + APP_SECRET + "\"," + | ||
(legacy ? " \"admin\": true," : " \"systemAdmin\": true,") + | ||
" \"creation\": {" + | ||
" \"user\": \"[email protected]\"," + | ||
" \"timestamp\": \"2018-04-10T09:58:20.032Z\"" + | ||
"}}"; | ||
} | ||
} |