public void GetIdentity_InvalidToken_ReturnsUnauthorized() { const string TOKEN = "some"; _jwtSecurityTokenHandlerMock.Setup(x => x.CanReadToken(TOKEN)).Returns(true); TokenValidationParameters passedParameters = null; var callback = new ValidateCallback((string t, TokenValidationParameters p, out SecurityToken st) => { st = null; passedParameters = p; }); SecurityToken token; _jwtSecurityTokenHandlerMock .Setup(h => h.ValidateToken(TOKEN, It.IsAny <TokenValidationParameters>(), out token)) .Callback(callback) .Throws(new Exception()); var result = _manager.GetIdentity(TOKEN); Assert.IsNotNull(result); Assert.IsFalse(result.IsAuthenticated); Assert.IsNotNull(passedParameters); Assert.IsTrue(passedParameters.RequireExpirationTime); Assert.IsTrue(passedParameters.ValidateLifetime); Assert.IsFalse(passedParameters.ValidateIssuer); Assert.IsFalse(passedParameters.ValidateAudience); AssertSecurityKey(passedParameters.IssuerSigningKey); }
public void GetIdentity_ValidToken_WorksAsExpected() { const string TOKEN = "some"; _jwtSecurityTokenHandlerMock.Setup(x => x.CanReadToken(TOKEN)).Returns(true); var principal = new ClaimsPrincipal(new ClaimsIdentity()); TokenValidationParameters passedParameters = null; var callback = new ValidateCallback((string t, TokenValidationParameters p, out SecurityToken st) => { st = null; passedParameters = p; }); SecurityToken token; _jwtSecurityTokenHandlerMock .Setup(h => h.ValidateToken(TOKEN, It.IsAny <TokenValidationParameters>(), out token)) .Callback(callback) .Returns(principal); var result = _manager.GetIdentity(TOKEN); Assert.IsNotNull(result); Assert.AreSame(principal.Identity, result); Assert.IsNotNull(passedParameters); Assert.IsTrue(passedParameters.RequireExpirationTime); Assert.IsTrue(passedParameters.ValidateLifetime); Assert.IsFalse(passedParameters.ValidateIssuer); Assert.IsFalse(passedParameters.ValidateAudience); AssertSecurityKey(passedParameters.IssuerSigningKey); }
public static void Show(Rect rect, Speech speech, ValidateCallback callback) { //Close window if already open if (window != null) { Hide(); return; } //Open window ClipPopup.callback = callback; ClipPopup.voiceUUID = speech.voiceUUID; clips = null; error = Error.None; window = CreateInstance <ClipPopup>(); window.ShowPopup(); window.minSize = rect.size; window.titleContent = new GUIContent("Voices"); window.position = rect; //Request clips List <string> existingClips = speech.clips.Select(x => x.uuid).ToList(); APIBridge.GetClips((ResembleClip[] clips, Error error) => { ClipPopup.clips = clips.Where(x => x.voice == voiceUUID && !existingClips.Contains(x.uuid)).ToArray(); ClipPopup.error = error; window.Repaint(); }); }
/// <summary> /// 与えられたクッキーでニコニコにログインできるか確かめます。 /// </summary> public static void BeginValidate(Cookie cookie, ValidateCallback callback, bool highPriority) { var cc = new CookieContainer(); cc.Add(cookie); BeginValidate(cc, callback, highPriority); }
public override bool Validate(ValidateCallback callback, StateHolder state) { if (callback == null) { throw new ArgumentNullException("callback"); } if (sourceLocationId <= 0) { if (!callback(Translator.GetString("Source location cannot be empty!"), ErrorSeverity.Error, (int)ErrorCodes.SourceLocationEmpty, state)) { return(false); } } if (BusinessDomain.LoggedUser.LockedLocationId > 0 && BusinessDomain.LoggedUser.LockedLocationId != sourceLocationId) { if (!callback(Translator.GetString("The source location cannot be used!"), ErrorSeverity.Error, (int)ErrorCodes.SourceLocationCannotBeUsed, state)) { return(false); } } string error; string warning; if (!BusinessDomain.CanUseLocationInOperation(OperationType, sourceLocationId, out error, out warning)) { if (error != null && !callback(error, ErrorSeverity.Error, (int)ErrorCodes.SourceLocationCannotBeUsed, state)) { return(false); } if (warning != null && !callback(error, ErrorSeverity.Warning, (int)ErrorCodes.SourceLocationCannotBeUsed, state)) { return(false); } } if (targetLocationId <= 0) { if (!callback(Translator.GetString("Target location cannot be empty!"), ErrorSeverity.Error, (int)ErrorCodes.TargetLocationEmpty, state)) { return(false); } } if (details.Any(d => d.Quantity.IsZero())) { if (!callback(Translator.GetString("Details contain zero quantities!"), ErrorSeverity.Error, (int)ErrorCodes.TargetLocationEmpty, state)) { return(false); } } return(true); }
public static void Show(ImpAsset[] assets, string path, ValidateCallback callback) { ImportPopup.path = Utils.LocalPath(path); ImportPopup.assets = assets; ImportPopup.callback = callback; RefreshAllCheck(); window = EditorWindow.CreateInstance <ImportPopup>(); window.ShowModalUtility(); window.titleContent = new GUIContent("Import"); window.minSize = new Vector2(200, 300); }
public bool Validate(ValidateCallback callback, StateHolder state) { if (callback == null) { throw new ArgumentNullException("callback"); } if (name.Length == 0) { if (!callback(Translator.GetString("User name cannot be empty!"), ErrorSeverity.Error, 0, state)) { return(false); } } User u = GetByName(name); if (u != null && u.Id != id) { if (!callback(string.Format(Translator.GetString("User with the name \"{0}\" already exists! Do you want to save the user anyway?"), name), ErrorSeverity.Warning, 1, state)) { return(false); } } if (!string.IsNullOrEmpty(code)) { u = GetByCode(code); if (u != null && u.Id != id) { if (!callback(string.Format(Translator.GetString("User with the code \"{0}\" already exists. Do you want to save the user anyway?"), code), ErrorSeverity.Warning, 2, state)) { return(false); } } } if (!string.IsNullOrEmpty(cardNo)) { u = GetByCard(cardNo); if (u != null && u.Id != id) { if (!callback(string.Format(Translator.GetString("User with the card \"{0}\" already exists. Do you want to save the user anyway?"), cardNo), ErrorSeverity.Warning, 3, state)) { return(false); } } } return(true); }
public override bool Validate(ValidateCallback callback, StateHolder state) { if (callback == null) { throw new ArgumentNullException("callback"); } if (string.IsNullOrEmpty(name)) { callback(Translator.GetString("Recipe name cannot be empty!"), ErrorSeverity.Error, 0, state); return(false); } return(true); }
public bool Validate(ValidateCallback callback, StateHolder state) { if (callback == null) { throw new ArgumentNullException("callback"); } if (name.Length == 0) { if (!callback(Translator.GetString("VAT group name cannot be empty!"), ErrorSeverity.Error, 0, state)) { return(false); } } if (vatValue == double.MinValue || vatValue < 0 || vatValue >= 100) { if (!callback(string.Format(Translator.GetString("VAT group \"{0}\" has invalid percent value!"), name), ErrorSeverity.Error, 1, state)) { return(false); } } VATGroup p = GetByName(name); if (p != null && p.Id != id) { if (!callback(string.Format(Translator.GetString("VAT group with the name \"{0}\" already exists! Do you want to save the vat group anyway?"), name), ErrorSeverity.Warning, 2, state)) { return(false); } } p = GetByCode(code); if (p != null && p.Id != id) { if (!callback(string.Format(Translator.GetString("VAT group with this code \"{0}\" already exists! Do you want to save the vat group anyway?"), code), ErrorSeverity.Warning, 3, state)) { return(false); } } return(true); }
public static void Show(Rect rect, ValidateCallback callback) { //Close window if already open if (window != null) { Hide(); return; } //Open window DeletePopup.callback = callback; window = CreateInstance <DeletePopup>(); window.ShowPopup(); window.minSize = new Vector2(100, 90); window.titleContent = new GUIContent("ChoicePopup"); window.position = rect; }
/// <summary> /// 与えられたクッキーでニコニコにログインできるか確かめます。 /// </summary> public static void BeginValidate(CookieContainer cc, ValidateCallback callback, bool highPriority) { var data = MakeData(cc, callback); if (data == null) { if (callback != null) { callback(cc, null); } return; } PushData(data, highPriority); }
public static void Show(Rect rect, ValidateCallback callback) { //Close window if already open if (window != null) { window.Close(); return; } //Open window VoicePopup.callback = callback; Settings.OnRefreshVoices += OnRefreshVoices; Settings.RefreshVoices(); voices = Settings.voices; window = CreateInstance <VoicePopup>(); window.ShowPopup(); window.titleContent = new GUIContent("Voices"); window.position = rect; }
public static void Show(Rect rect, string title, string value, ValidateCallback callback) { //Close window if already open if (window != null) { Hide(); return; } //Open window StringPopup.value = value; StringPopup.fieldTitle = title; StringPopup.callback = callback; window = CreateInstance <StringPopup>(); window.ShowPopup(); window.minSize = new Vector2(100, 70); window.titleContent = new GUIContent("StringFieldPopup"); window.position = rect; }
public bool Validate(ValidateCallback callback, StateHolder state) { if (callback == null) { throw new ArgumentNullException("callback"); } if (string.IsNullOrEmpty(name)) { if (!callback(Translator.GetString("Location name cannot be empty!"), ErrorSeverity.Error, 0, state)) { return(false); } } Location p = GetByName(name); if (p != null && p.Id != id) { if (!callback(string.Format(Translator.GetString("Location with the name \"{0}\" already exists! Do you want to save the location anyway?"), name), ErrorSeverity.Warning, 1, state)) { return(false); } } if (!string.IsNullOrEmpty(code)) { p = GetByCode(code); if (p != null && p.Id != id) { if (!callback(string.Format(Translator.GetString("Location with the code \"{0}\" already exists. Do you want to save the location anyway?"), code), ErrorSeverity.Warning, 2, state)) { return(false); } } } return(true); }
public bool Validate(ValidateCallback callback, StateHolder state) { if (string.IsNullOrWhiteSpace(ItemName)) { if (!callback(Translator.GetString("Item name cannot be empty!"), ErrorSeverity.Error, 0, state)) { return(false); } } ResolvedItem = Item.GetByAny(ItemName); if (ResolvedItem == null) { if (!callback(string.Format(Translator.GetString("Item \"{0}\" cannot be found!"), ItemName), ErrorSeverity.Error, 0, state)) { return(false); } } return(true); }
/// <summary> /// 内部データを作成します。 /// </summary> private static InternalData MakeData(CookieContainer cc, ValidateCallback callback) { var userId = AccountInfo.GetUserIdFromCookie(cc); if (userId < 0) { return null; } if (callback == null) { return null; } return new InternalData() { CookieContainer = cc, UserId = userId, Callback = callback, }; }
/// <summary> /// 内部データを作成します。 /// </summary> private static InternalData MakeData(CookieContainer cc, ValidateCallback callback) { var userId = AccountInfo.GetUserIdFromCookie(cc); if (userId < 0) { return(null); } if (callback == null) { return(null); } return(new InternalData() { CookieContainer = cc, UserId = userId, Callback = callback, }); }
public bool Validate(ValidateCallback callback, StateHolder state) { if (callback == null) { throw new ArgumentNullException("callback"); } if (string.IsNullOrEmpty(Name) && !callback(Translator.GetString("The name of a price rule must not be empty."), ErrorSeverity.Error, 0, state)) { return(false); } if (conditions.FindAll(condition => condition.IsActive).Count == 0 && !callback(Translator.GetString("A price rule must contain at least one condition."), ErrorSeverity.Error, 0, state)) { return(false); } if (actions.FindAll(action => action.IsActive).Count == 0 && !callback(Translator.GetString("A price rule must contain at least one action."), ErrorSeverity.Error, 0, state)) { return(false); } if (operations.Count == 0 && !callback(Translator.GetString("A price rule must contain at least one operation."), ErrorSeverity.Error, 0, state)) { return(false); } return(true); }
public bool Validate(ValidateCallback callback, StateHolder state) { if (callback == null) { throw new ArgumentNullException("callback"); } if (string.IsNullOrWhiteSpace(name)) { if (!callback(Translator.GetString("Item name cannot be empty!"), ErrorSeverity.Error, (int)ErrorCodes.NameEmpty, state)) { return(false); } } if (string.IsNullOrWhiteSpace(mUnit)) { if (!callback(string.Format(Translator.GetString("Measurement unit for item \"{0}\" is empty! Do you want to use the default one?"), name), ErrorSeverity.Warning, (int)ErrorCodes.MeasUnitEmpty, state)) { return(false); } mUnit = Translator.GetString("pcs."); } if (barCode3 != null && barCode3.Length > 254) { if (!callback(string.Format(Translator.GetString("There are too many additional barcodes! The excess barcodes will not be saved. Do you want to save the item anyway?"), name), ErrorSeverity.Warning, (int)ErrorCodes.TooManyBarcodes, state)) { return(false); } } Item g = GetByName(name); if (g != null && g.Id != id) { if (!callback(string.Format(Translator.GetString("Item with the name \"{0}\" already exists! Do you want to save the item anyway?"), name), ErrorSeverity.Warning, (int)ErrorCodes.NameInUse, state)) { return(false); } } if (!string.IsNullOrEmpty(code)) { g = GetByCode(code); if (g != null && g.Id != id) { if (!callback(string.Format(Translator.GetString("Item with the code \"{0}\" already exists. Do you want to save the item anyway?"), code), ErrorSeverity.Warning, (int)ErrorCodes.CodeInUse, state)) { return(false); } } } bool isDupl = false; string duplCode = string.Empty; if (barCode.Length > 0) { g = GetByBarCode(barCode); if (g != null && g.Id != id) { isDupl = true; } if (!isDupl && barCode2.Length > 0 && barCode == barCode2) { isDupl = true; } if (!isDupl && barCode3.Length > 0 && barCode == barCode3) { isDupl = true; } if (isDupl) { duplCode = barCode; } } if (!isDupl && barCode2.Length > 0) { g = GetByBarCode(barCode2); if (g != null && g.Id != id) { isDupl = true; } if (!isDupl && barCode3.Length > 0 && barCode2 == barCode3) { isDupl = true; } if (isDupl) { duplCode = barCode2; } } if (!isDupl && barCode3.Length > 0) { g = GetByBarCode(barCode3); if (g != null && g.Id != id) { isDupl = true; duplCode = barCode; } } if (isDupl) { if (!callback(string.Format(Translator.GetString("The barcode \"{0}\" already exists. Do you want to save the item anyway?"), duplCode), ErrorSeverity.Warning, (int)ErrorCodes.BarcodeInUse, state)) { return(false); } } return(true); }
public bool Validate(ValidateCallback callback, StateHolder state) { return(customer.Validate(callback, state)); }
public static void Show(Rect rect, string title, ValidateCallback callback) { Show(rect, title, "", callback); }
public ValidateEventArgs(ValidateCallback callback, StateHolder state) { this.callback = callback; this.state = state; }