mirror of https://github.com/halo-dev/halo
feat: add support for OpenHarmony in device OS detection (#7045)
#### What type of PR is this? /kind feature #### What this PR does / why we need it: This PR adds support for detecting OpenHarmony as a device operating system. #### Which issue(s) this PR fixes: Fixes #7039 #### Special notes for your reviewer: This PR introduces minor changes in the device OS detection logic. #### Does this PR introduce a user-facing change? ```release-note 新设备登录通知的操作系统名支持展示鸿蒙替代 Unknown ```pull/7057/head
parent
06f3c289e8
commit
2c8f6f5009
|
@ -192,12 +192,14 @@ public class DeviceServiceImpl implements DeviceService {
|
|||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
static final Pattern OS_REGEX =
|
||||
Pattern.compile("(Windows NT|Mac OS X|Android|Linux|iPhone|iPad|Windows Phone)");
|
||||
Pattern.compile(
|
||||
"(Windows NT|Mac OS X|Android|Linux|iPhone|iPad|Windows Phone|OpenHarmony)");
|
||||
static final Pattern[] osRegexes = {
|
||||
Pattern.compile("Windows NT (\\d+\\.\\d+)"),
|
||||
Pattern.compile("Mac OS X (\\d+[\\._]\\d+([\\._]\\d+)?)"),
|
||||
Pattern.compile("iPhone OS (\\d+_\\d+(_\\d+)?)"),
|
||||
Pattern.compile("Android (\\d+\\.\\d+(\\.\\d+)?)")
|
||||
Pattern.compile("Android (\\d+\\.\\d+(\\.\\d+)?)"),
|
||||
Pattern.compile("OpenHarmony (\\d+\\.\\d+(\\.\\d+)?)")
|
||||
};
|
||||
|
||||
public static DeviceInfo parse(String userAgent) {
|
||||
|
|
|
@ -2,7 +2,10 @@ package run.halo.app.security.device;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Tests for {@link DeviceServiceImpl}.
|
||||
|
@ -12,13 +15,29 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
class DeviceServiceImplTest {
|
||||
|
||||
@Test
|
||||
void deviceInfoParseTest() {
|
||||
var info = DeviceServiceImpl.DeviceInfo.parse(
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like "
|
||||
+ "Gecko) Chrome/126.0.0.0 Safari/537.36");
|
||||
assertThat(info.os()).isEqualTo("Mac OS X 10.15.7");
|
||||
assertThat(info.browser()).isEqualTo("Chrome 126.0");
|
||||
static Stream<Arguments> deviceInfoParseTest() {
|
||||
return Stream.of(
|
||||
Arguments.of(
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like "
|
||||
+ "Gecko) Chrome/126.0.0.0 Safari/537.36",
|
||||
"Mac OS X 10.15.7",
|
||||
"Chrome 126.0"
|
||||
),
|
||||
Arguments.of(
|
||||
"Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
+ "Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile HuaweiBrowser/5.0.4"
|
||||
+ ".300",
|
||||
"OpenHarmony 5.0",
|
||||
"Chrome 114.0"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void deviceInfoParseTest(String userAgent, String expectedOs, String expectedBrowser) {
|
||||
var info = DeviceServiceImpl.DeviceInfo.parse(userAgent);
|
||||
assertThat(info.os()).isEqualTo(expectedOs);
|
||||
assertThat(info.browser()).isEqualTo(expectedBrowser);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue