-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from yushijinhun/develop
Release 1.1.34
- Loading branch information
Showing
7 changed files
with
146 additions
and
7 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
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
49 changes: 49 additions & 0 deletions
49
src/main/java/moe/yushi/authlibinjector/transform/support/AuthServerNameInjector.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,49 @@ | ||
/* | ||
* Copyright (C) 2020 Haowei Wen <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package moe.yushi.authlibinjector.transform.support; | ||
|
||
import static moe.yushi.authlibinjector.util.Logging.log; | ||
import moe.yushi.authlibinjector.APIMetadata; | ||
import moe.yushi.authlibinjector.util.Logging.Level; | ||
|
||
public final class AuthServerNameInjector { | ||
private AuthServerNameInjector() {} | ||
|
||
private static String getServerName(APIMetadata meta) { | ||
Object serverName = meta.getMeta().get("serverName"); | ||
if (serverName instanceof String) { | ||
return (String) serverName; | ||
} else { | ||
return meta.getApiRoot(); | ||
} | ||
} | ||
|
||
public static void init(APIMetadata meta) { | ||
MainArgumentsTransformer.getArgumentsListeners().add(args -> { | ||
for (int i = 0; i < args.length - 1; i++) { | ||
if ("--versionType".equals(args[i])) { | ||
String serverName = getServerName(meta); | ||
log(Level.DEBUG, "Setting versionType to server name: " + serverName); | ||
args[i + 1] = serverName; | ||
break; | ||
} | ||
} | ||
return args; | ||
}); | ||
} | ||
|
||
} |
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
60 changes: 60 additions & 0 deletions
60
src/test/java/moe/yushi/authlibinjector/test/SkinWhitelistTest.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,60 @@ | ||
/* | ||
* Copyright (C) 2020 Haowei Wen <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package moe.yushi.authlibinjector.test; | ||
|
||
import static moe.yushi.authlibinjector.transform.support.SkinWhitelistTransformUnit.domainMatches; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
|
||
public class SkinWhitelistTest { | ||
|
||
@Test | ||
public void testEmptyPattern() { | ||
assertFalse(domainMatches("", "example.com")); | ||
} | ||
|
||
@Test | ||
public void testDotMatchesSubdomain() { | ||
assertTrue(domainMatches(".example.com", "a.example.com")); | ||
} | ||
|
||
@Test | ||
public void testDotMatchesSubdomain2() { | ||
assertTrue(domainMatches(".example.com", "b.a.example.com")); | ||
} | ||
|
||
@Test | ||
public void testDotNotMatchesToplevel() { | ||
assertFalse(domainMatches(".example.com", "example.com")); | ||
} | ||
|
||
@Test | ||
public void testNonDotMatchesToplevel() { | ||
assertTrue(domainMatches("example.com", "example.com")); | ||
} | ||
|
||
@Test | ||
public void testNonDotNotMatchesSubdomain() { | ||
assertFalse(domainMatches("example.com", "a.example.com")); | ||
} | ||
|
||
@Test | ||
public void testNonDotNotMatchesOther() { | ||
assertFalse(domainMatches("example.com", "eexample.com")); | ||
} | ||
} |