-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(open-api): get authorized apps #3647
Merged
nobodyiam
merged 20 commits into
apolloconfig:master
from
Anilople:feature/openapi/enhancement/20210417
Jun 26, 2021
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ecda570
feat(open-api): get authorized apps
Anilople 29fa187
Merge branch 'master' into feature/openapi/enhancement/20210417
Anilople 1c1522d
Merge branch 'master' into feature/openapi/enhancement/20210417
nobodyiam f0931c6
Merge branch 'master' into feature/openapi/enhancement/20210417
Anilople 4d41625
refactor: delete new class
Anilople f3adccd
fix: test failure
Anilople 472dd45
rename method name
Anilople 5cacf99
Merge branch 'master' into feature/openapi/enhancement/20210417
Anilople 73f4c01
Merge branch 'master' into feature/openapi/enhancement/20210417
Anilople c1d7cbd
fix: extractAppIdFromMasterRoleName -> extractAppIdFromRoleName
Anilople f9cdb84
test: find app authorized
Anilople 1d45338
Merge branch 'master' into feature/openapi/enhancement/20210417
Anilople f4d182b
Update CHANGES.md
Anilople 11d39b3
refactor: create method findAppIdsAuthorizedByConsumerId in ConsumerS…
Anilople 1ddc81c
test: use sql to prepare data
Anilople 348af40
test: add more app consumer-test-app-id-2
Anilople 99822cb
test: restTemplate call api with token
Anilople dea5f3c
test: append 000 to all id in sql
Anilople c284ae5
test: move sql to folder /sql/openapi
Anilople 5a999dc
Merge branch 'master' into feature/openapi/enhancement/20210417
nobodyiam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
45 changes: 45 additions & 0 deletions
45
.../test/java/com/ctrip/framework/apollo/openapi/service/ConsumerServiceIntegrationTest.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,45 @@ | ||
/* | ||
* Copyright 2021 Apollo Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.ctrip.framework.apollo.openapi.service; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
import com.ctrip.framework.apollo.portal.AbstractIntegrationTest; | ||
import com.google.common.collect.Sets; | ||
import java.util.Set; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
/** | ||
* @author wxq | ||
*/ | ||
public class ConsumerServiceIntegrationTest extends AbstractIntegrationTest { | ||
|
||
@Autowired | ||
private ConsumerService consumerService; | ||
|
||
@Test | ||
@Sql(scripts = "/sql/openapi/ConsumerServiceIntegrationTest.testFindAppIdsAuthorizedByConsumerId.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
public void testFindAppIdsAuthorizedByConsumerId() { | ||
Set<String> appIds = this.consumerService.findAppIdsAuthorizedByConsumerId(1000L); | ||
assertEquals(Sets.newHashSet("consumer-test-app-id-0", "consumer-test-app-id-1"), appIds); | ||
assertFalse(appIds.contains("consumer-test-app-id-2")); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...t/java/com/ctrip/framework/apollo/openapi/v1/controller/AppControllerIntegrationTest.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,63 @@ | ||
/* | ||
* Copyright 2021 Apollo Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.ctrip.framework.apollo.openapi.v1.controller; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO; | ||
import com.ctrip.framework.apollo.portal.AbstractIntegrationTest; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.junit.Test; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
/** | ||
* Integration test for {@link AppController}. | ||
* | ||
* @author wxq | ||
*/ | ||
public class AppControllerIntegrationTest extends AbstractIntegrationTest { | ||
|
||
@Test | ||
@Sql(scripts = "/sql/openapi/ConsumerServiceIntegrationTest.testFindAppIdsAuthorizedByConsumerId.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
public void testFindAppsAuthorized() { | ||
final String token = "3c16bf5b1f44b465179253442460e8c0ad845289"; | ||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
httpHeaders.set(HttpHeaders.AUTHORIZATION, token); | ||
|
||
ResponseEntity<OpenAppDTO[]> responseEntity = | ||
restTemplate.exchange(this.url("/openapi/v1/apps/authorized"), HttpMethod.GET, | ||
new HttpEntity<>(httpHeaders), OpenAppDTO[].class); | ||
|
||
OpenAppDTO[] openAppDTOS = responseEntity.getBody(); | ||
assertEquals(2, openAppDTOS.length); | ||
|
||
Set<String> appIds = new HashSet<>(); | ||
for (OpenAppDTO openAppDTO : openAppDTOS) { | ||
appIds.add(openAppDTO.getAppId()); | ||
} | ||
|
||
assertTrue(appIds.contains("consumer-test-app-id-0")); | ||
assertTrue(appIds.contains("consumer-test-app-id-1")); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to set token by this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok
btw, is the following sql necessary? I think every test should clean its data after execution, so there is no need to clear the data before execution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we delete the cleanup before run this test, code chagne to
and run a single test
AppControllerIntegrationTest
, will meet errororg.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.PERMISSION(ID)";
full log as follow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, there is an initialization logic in
com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultRoleInitializationService#initCreateAppRole
which will create one set of role, permission and role permission record. I think we could change the id in the test sql.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, is it better to organize the sql file into the sql folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have been moved to folder
resources/sql/openapi